[英]Black screen when dismissing a UIViewController with custom transition from within a UINavigationController
I have a view controller FromViewController
and I want it to present a ToViewController
with a custom transition. 我有一个视图控制器
FromViewController
,我希望它提供一个自定义转换的ToViewController
。 I have implemented the UIViewControllerAnimatedTransitioning
for both the to- and from-transitions and it's all working nicely when I present and dismiss the ToViewController
. 我已经为to-和from-transitions实现了
UIViewControllerAnimatedTransitioning
,当我出现并解除ToViewController
时,它们ToViewController
。
However, if my FromViewController
is contained within a UINavigationController
I just get a black screen when I dismiss the ToViewController
. 但是,如果我的
FromViewController
包含在UINavigationController
当我解除ToViewController
时,我只会得到一个黑屏。
This is the code from the UIViewControllerAnimatedTransitioning
when dismissing: 解雇时,这是来自
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
}
I have inspected the app and it seems that neither the UINavigationController
nor FromViewController
are in the view hierarchy after the dismissal. 我已经检查了应用程序,似乎在解雇后
UINavigationController
和FromViewController
都不在视图层次结构中。
I figured it out. 我想到了。 The problem was when I was adding the view to the transition context container view:
问题是当我将视图添加到转换上下文容器视图时:
[self.containerView insertSubview:self.fromViewController.view belowSubview:self.toViewController.view];
In stead I needed to add the view from the navigation controller: 而我需要从导航控制器添加视图:
[self.containerView insertSubview:navigationController.view belowSubview:self.toViewController.view];
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.