Black screen when rejecting a UIViewController with a custom transition from the UINavigationController

I have a view controller FromViewController, and I want it to present ToViewControllerwith a custom transition. I implemented UIViewControllerAnimatedTransitioningfor both to and transitions, and it all works great when I submit and reject ToViewController.

However, if mine is FromViewControllercontained in UINavigationController, I just get a black screen when I reject ToViewController.

This is the code from UIViewControllerAnimatedTransitioningupon dismissal:

- (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 looked over the app, and it seems that neither of UINavigationControllerand FromViewControlleris not in a hierarchy of ideas after the dismissal.

+4
source share
1

. , :

 [self.containerView insertSubview:self.fromViewController.view belowSubview:self.toViewController.view];

:

[self.containerView insertSubview:navigationController.view belowSubview:self.toViewController.view];
+2

Source: https://habr.com/ru/post/1691324/


All Articles