简体   繁体   中英

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. 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 .

However, if my FromViewController is contained within a UINavigationController I just get a black screen when I dismiss the ToViewController .

This is the code from the UIViewControllerAnimatedTransitioning when dismissing:

- (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.

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];

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM