【问题标题】:UIStoryBoardSegue transition - Status bar issueUIStoryBoardSegue 过渡 - 状态栏问题
【发布时间】:2014-10-07 19:44:59
【问题描述】:

我正在尝试使用 UIStoryboardSegue 子类创建到新视图控制器的自定义转换,但我遇到了一些问题。我有一个后退按钮,它使用 AutoLayout 设置为距离顶部布局指南 5 像素(基本上距离视图顶部 25 像素)。但是,当我在转换时,我的视图没有考虑到状态栏的存在,并使按钮距视图顶部 5 像素而不是距视图顶部 25 像素(status-bar.height = = 20 像素)。因此,当我调用 [[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"];

}

【问题讨论】:

    标签: ios storyboard autolayout


    【解决方案1】:

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

    【讨论】:

    • setNeedsLayout 不起作用。我尝试在目标视图控制器的 viewWillAppear 中调用它,并且在将目标视图添加到源视图的父视图后,我还在 UIStoryBoardSegue 子类中尝试了它。
    • 问题与 topLayoutGuide 有关。我对其进行了测试以确保。当我过境时,topLayoutGuide 为 0,而在目标视图控制器的 viewDidAppear 中,topLayoutGuide 为 20,这是应该的。关于为什么会这样的想法?
    • 我发现了一个类似的问题here。希望对你有帮助。
    猜你喜欢
    • 1970-01-01
    • 2013-10-10
    • 2015-09-03
    • 2011-11-24
    • 2013-10-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多