【发布时间】: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