我有一个视图控制器FromViewController
,我希望它提供一个带有自定义转换的ToViewController
。我已经为转换和转换实现了UIViewControllerAnimatedTransitioning
,当我出现并关闭ToViewController
时,它们都很好用。
但是,如果我的FromViewController
包含在UINavigationController
中,那么当我关闭ToViewController
时,我只会出现黑屏。
这是解雇时UIViewControllerAnimatedTransitioning
的代码:
- (void)animateTransition:(nonnull id<UIViewControllerContextTransitioning>)transitionContext {
self.toViewController = (ToViewController *)
[transitionContext viewControllerForKey:UITransitionContextFromViewControllerKey];
UINavigationController *navigationController = [transitionContext viewControllerForKey:UITransitionContextToViewControllerKey];
self.fromViewController = (FromViewController *)navigationController.topViewController;
self.containerView = transitionContext.containerView;
[self.containerView insertSubview:self.fromViewController.view belowSubview:self.toViewController.view];
// My animations go here
// In the animation completion block I call:
[transitionContext completeTransition:!transitionContext.transitionWasCancelled]; // this is when my screen goes black
}
我检查了应用程序,似乎解雇后UINavigationController
和FromViewController
都不在视图层次结构中。
答案 0 :(得分:2)
我明白了。问题是当我将视图添加到转换上下文容器视图时:
[self.containerView insertSubview:self.fromViewController.view belowSubview:self.toViewController.view];
我需要从导航控制器添加视图:
[self.containerView insertSubview:navigationController.view belowSubview:self.toViewController.view];