0

I'm trying to create a custom transition to a new view controller using a UIStoryboardSegue subclass, but I'm having some issues. I have a back button that's setup to with AutoLayout to be 5 pixels from the top layout guide (essentially 25 pixels from the top of the view). However, when I'm transiting my view doesn't take into account that the status bar exists and makes the button 5 pixels away from the top of the view instead of 25 pixels away from the top of view (status-bar.height == 20px). So when the transition finishes theres a sudden bounce when I call [[self sourceViewController] presentModalViewController:[self destinationViewController] animated:NO]; because then the button will actually be layer out correctly. Does anyone have any ideas how I can tell my view that it should layout assuming that the top layout guide starts at 20px instead of 0?

Edit: The issues seems to be directly related to the topLayoutGuide. When checking the value of topLayoutGuide it was 0 when I added the view in the transition, but when I checked it in the destination view controller's viewDidAppear it was 20 like it was supposed to be.

- (void)perform {
UIWindow *window = [[[UIApplication sharedApplication] windows] objectAtIndex:0];
UIViewController *sourceViewController = (UIViewController*)self.sourceViewController;
UIViewController *destinationViewController = (UIViewController*)self.destinationViewController;

[destinationViewController.view setCenter:CGPointMake(window.frame.size.width * 1.5, sourceViewController.view.center.y)];
[[sourceViewController.view superview] addSubview:destinationViewController.view];
[destinationViewController.view setBackgroundColor:[UIColor redColor]];

POPSpringAnimation *positionAnimation = [POPSpringAnimation animationWithPropertyNamed:kPOPLayerPositionX];
positionAnimation.toValue = @(window.center.x);
positionAnimation.springBounciness = 10;


POPSpringAnimation *fromPositionAnimation = [POPSpringAnimation animationWithPropertyNamed:kPOPLayerPositionX];
double offScreenX = -sourceViewController.view.frame.size.width;
fromPositionAnimation.toValue = @(offScreenX);
fromPositionAnimation.springBounciness = 10;
[fromPositionAnimation setCompletionBlock:^(POPAnimation *anim, BOOL finished) {
}];

POPSpringAnimation *scaleAnimation = [POPSpringAnimation animationWithPropertyNamed:kPOPLayerScaleXY];
scaleAnimation.springBounciness = 20;
scaleAnimation.fromValue = [NSValue valueWithCGPoint:CGPointMake(1.0, 1.1)];
[scaleAnimation setCompletionBlock:^(POPAnimation *anim, BOOL finished) {
    [[self sourceViewController] presentModalViewController:[self destinationViewController] animated:NO];
}];

[sourceViewController.view.layer pop_addAnimation:fromPositionAnimation forKey:@"positionAnimation"];
[destinationViewController.view.layer pop_addAnimation:positionAnimation forKey:@"positionAnimation"];
[destinationViewController.view.layer pop_addAnimation:scaleAnimation forKey:@"scaleAnimation"];

}

enter image description here

Homeschooldev
  • 405
  • 1
  • 7
  • 18

1 Answers1

0

I suggest call setNeedLayout on viewWillAppear. It's should adjust the layout of a view’s subviews.

Alex
  • 35
  • 6
  • setNeedsLayout didn't work. I tried calling it within the viewWillAppear on the destination view controller and I also tried it in the UIStoryBoardSegue subclass after adding the destination view to the source view's superview. – Homeschooldev Oct 07 '14 at 20:19
  • The issue is related to the topLayoutGuide. I tested it to make sure. When I'm transiting the topLayoutGuide is 0 and in viewDidAppear for the destination view controller the topLayoutGuide is 20, which is what it should be. Ideas on why this is? – Homeschooldev Oct 07 '14 at 20:45
  • I found a similar problem [here](http://stackoverflow.com/questions/20312765/navigation-controller-top-layout-guide-not-honored-with-custom-transition). I hope it help you. – Alex Oct 07 '14 at 21:53