UIStoryBoardSegue过渡 - 状态栏问题

时间:2014-10-07 19:45:00

标签: ios storyboard autolayout

我正在尝试使用UIStoryboardSegue子类创建到新视图控制器的自定义转换,但我遇到了一些问题。我有一个后退按钮设置为AutoLayout距离顶部布局指南5个像素(基本上是视图顶部的25个像素)。但是,当我转换我的视图时没有考虑状态栏是否存在并使按钮距离视图顶部5个像素而不是距离视图顶部25个像素(status-bar.height = = 20px)。因此,当我调用[[self sourceViewController] presentModalViewController:[self destinationViewController] animated:NO]时,当转换结束时突然反弹。因为那时按钮实际上会正确分层。有没有人有任何想法我怎么能告诉我的观点,它应该布局假设顶部布局指南从20px而不是0开始?

编辑:问题似乎与topLayoutGuide直接相关。在检查topLayoutGuide的值时,当我在转换中添加视图时它是0,但是当我在目标视图控制器的viewDidAppear中检查它时,它就像它应该的那样20。

- (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

1 个答案:

答案 0 :(得分:0)

我建议在viewWillAppear上调用setNeedLayout。它应该调整视图子视图的布局。