简体   繁体   English

从UINavigationController中解除具有自定义转换的UIViewController时出现黑屏

[英]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. 我已经检查了应用程序,似乎在解雇后UINavigationControllerFromViewController都不在视图层次结构中。

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.

相关问题 对子类UINavigationController使用自定义iOS 7过渡有时会导致黑屏 - Using custom iOS 7 transition with subclassed UINavigationController occasionally results in black screen 如何从UIViewController过渡到UINavigationController - How to transition to a UINavigationController from a UIViewController (iOS)自定义初始化UIViewController时出现黑屏 - (iOS) Black screen when custom initializing UIViewController 从UIViewController调用自定义UINavigationController中的方法时目标错误 - Wrong target when calling method in custom UINavigationController from UIViewController UINavigationController的自定义Segue显示黑屏 - Custom Segue to UINavigationController shows black screen iOS-从UINavigationController中以全屏显示UIViewController - iOS - Display a UIViewController as fullscreen from within a UINavigationController 自定义UIViewController子类仅显示黑屏 - Custom UIViewController subclass only shows a black screen 自定义过渡导致黑屏或无响应的屏幕 - Custom transition results in black screen or unresponsive screen 以编程方式执行操作时,UIViewController显示为黑屏 - UIViewController appears as Black screen when doing programmatically 单击自定义TableView单元格后,UINavigationController显示黑屏 - UINavigationController is showing black screen after clicking on custom TableView cell
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM