我在我的应用程序中实现了自定义 UIViewController Transition,它取代了推送动画中内置的导航控制器。
到目前为止,一切正常,除了新推送的视图控制器中的 toplayoutguide 为 0,尽管新视图控制器继承了旧视图控制器的导航栏。
它应该是 64.0(状态栏高度 + 导航栏高度),现在是 0.0。
因此,附加到情节提要中顶部布局指南的所有对象现在都显得太高 64 点(在半透明栏下方)。
当我禁用自定义视图转换时,顶部布局指南将具有预期值。
我尝试“到处”调用layoutSubviews和updateConstraints。在视图控制器和导航控制器中。
据我了解,导航控制器(parentviewcontroller)应该更新新视图控制器的 toplayoutguide,但显然我在自定义转换代码中缺少一些内容,这会触发 toplayoutguide 更新为正确的值。
这是我的自定义转换代码,它是设置为导航控制器委托的对象:
- (NSTimeInterval)transitionDuration:(id<UIViewControllerContextTransitioning>)transitionContext
{
return 0.7;
}
- (void)animateTransition:(id<UIViewControllerContextTransitioning>)transitionContext
{
UIView *animationContainerView = [transitionContext containerView];
UIViewController *toVC = [transitionContext viewControllerForKey:UITransitionContextToViewControllerKey];
UIView *toView = [toVC view];
UIViewController *fromVC = [transitionContext viewControllerForKey:UITransitionContextFromViewControllerKey];
UIView *fromView = [fromVC view];
CGRect endFrame = [transitionContext finalFrameForViewController:toVC];
CGRect startFrame;
startFrame = CGRectOffset(endFrame, 0, endFrame.size.height);
if (self.operation == UINavigationControllerOperationPop) {
[animationContainerView insertSubview:toView belowSubview:fromView];
[toView setFrame:endFrame];
}
else{
[toView setFrame:startFrame];
[animationContainerView insertSubview:toView aboveSubview:fromView];
}
[UIView animateWithDuration:[self transitionDuration:transitionContext] delay:0.0 usingSpringWithDamping:0.7 initialSpringVelocity:0.8 options:UIViewAnimationOptionBeginFromCurrentState animations:^{
if (self.operation == UINavigationControllerOperationPop) {
[fromView setFrame:startFrame];
[fromView layoutIfNeeded];
}
else{
[toView setFrame:endFrame];
[toView layoutIfNeeded];
}
} completion:^(BOOL finished) {
[transitionContext completeTransition:YES];
}];
}
那里没有什么真正奇妙的事情发生。只是视图从下往上滑动,带有一些内置的动态。
问题是,附加到顶部布局指南的对象现在位于导航栏下方,因为顶部布局指南长度 == 0。
我不知道我需要做什么,以便将视图控制器的 toplayoutguide 设置为正确的值。
推送导航是通过推送故事板转场“普通”执行的。在调用 PerformSegueWithIdentifier 之前,我所做的就是设置导航控制器委托。
这是代码:
self.navigationController.delegate = [[My_CustomNavigationTransitionDelegate alloc] init];
[self performSegueWithIdentifier:@"infosSegue" sender:nil];
我想念什么?