Animating the presenting view in a UIPresentationController

后端 未结 2 1171
遥遥无期
遥遥无期 2021-01-03 17:05

For some context, I recommend reading this:

Very relevant question: "From View Controller" disappears using UIViewControllerContextTransitioning Very relev

2条回答
  •  抹茶落季
    2021-01-03 17:30

    Why are you setting shouldRemovePresentersView to YES if what you want is that the fromView remains visible?

    I had the same problem as you, as in my custom 3d presentation the parent view controller was removed as soon as the transition was completed.

    The solution there is to change the modalPresentationStyle to UIModalPresentationOverCurrentContext This will specifically prohibit the system to remove the owner viewController when the transition ends.

    Still my 3D transition suffered from animation issues, when using this approach.

    Si I ended up using a UIModalPresentationCustom modalPresentationStyle which solved almost all my issues, with the exception that the new view controller (which was a UINavigationController) would not move down when the in-call status bar would appear.

    To solve this, I ended up changing the modalPresentationStyle back to UIModalPresentationFullScreen after the transition had been completed.

    Here is my code that shows the new viewController with the custom presentation:

    //show Login Screen
    LoginViewController *viewController = [[LoginViewController alloc] initWithNibName:@"LoginViewController" bundle:nil];
    
    UINavigationController *loginNavController = [[UINavigationController alloc] initWithRootViewController:viewController];
    loginNavController.interactivePopGestureRecognizer.enabled = YES;
    loginNavController.transitioningDelegate = self.customTransitionDelegate;
    loginNavController.modalPresentationStyle = UIModalPresentationCustom;
    
    [navigationController presentViewController:loginNavController animated:YES
                                     completion:^{
                                         //important, else status bar is not moving entire screen down....
                                         loginNavController.modalPresentationStyle = UIModalPresentationFullScreen;
                                     }
     ];
    

    Also very important is that you must NOT add the old view to the containerView when you run your dismissal animation

    So if the animation is the presenting, add your toView to the containerView

        UIView* inView = [transitionContext containerView];
    
        UIViewController* toViewController = [transitionContext viewControllerForKey:UITransitionContextToViewControllerKey];
        UIViewController* fromViewController = [transitionContext viewControllerForKey:UITransitionContextFromViewControllerKey];
    .....
    ......
    
        [inView insertSubview:toViewController.view aboveSubview:fromViewController.view];
    

    But on the dismissal presentation DO NOT ADD the view to the containerView as it is still showing (since we specifically asked the system NOT to remove it), but simply animate between the two views.

提交回复
热议问题