从UINavigationController中解除具有自定义转换的UIViewController时出现黑屏
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了从UINavigationController中解除具有自定义转换的UIViewController时出现黑屏相关的知识,希望对你有一定的参考价值。
我有一个视图控制器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
都不在视图层次结构中。
答案
我想到了。问题是当我将视图添加到转换上下文容器视图时:
[self.containerView insertSubview:self.fromViewController.view belowSubview:self.toViewController.view];
而我需要从导航控制器添加视图:
[self.containerView insertSubview:navigationController.view belowSubview:self.toViewController.view];
以上是关于从UINavigationController中解除具有自定义转换的UIViewController时出现黑屏的主要内容,如果未能解决你的问题,请参考以下文章