![](/img/trans.png)
[英]Using custom iOS 7 transition with subclassed UINavigationController occasionally results in black screen
[英]Black screen when dismissing a UIViewController with custom transition from within a UINavigationController
我有一個視圖控制器FromViewController
,我希望它提供一個自定義轉換的ToViewController
。 我已經為to-和from-transitions實現了UIViewControllerAnimatedTransitioning
,當我出現並解除ToViewController
時,它們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];
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.