uinavigationcontrollerdelegatescontextmenuios14custom-transition

two different custom transitions in a navigationController


I'm trying to make two different custom transition (one fade and one slide from top) within a navigation controller.
enter image description here

The transition works very well the first time but when pop the transitions acting crazy. I guess that navigationController.delegate is the key but I can't figure it out by myself. Any help will be greatly appreciated thanks a lot

******************************** IOS14 QUESTION UPDATE *****************************************

the solution of @Vlad for setting the delegate is working great thanks.

But recently in IOS14 a stack menu appearing when a long press gesture is detected on navigation back button (which allows user to navigate through the navigationcontroller's viewcontrollers stack).

And so the navigationcontroller delegate is setting to the wrong controller when popping two or more controllers.

I am once again asking for your support


Solution

  • Your starting state is in VC A. After viewDidLoad, the navigationController?.delegate is set to VC A which uses anim1. When you push to B, you're setting navigationController?.delegate to B, which uses anim2.

    When you pop from C to B, anim2 is used as navigationController?.delegate is VC B. When you pop from B to A, anim2 is used because navigationController?.delegate is still VC B.

    When you pop B, navigationController?.delegate is set to nil because the instance of VC B is destroyed. That is why when you try and push B again, the default animation is used.

    Two important pieces of information is that:

    1. viewDidLoad is only called one time when the view has finished loading and not when it appears again after a pop.
    2. navigationController?.delegate can only point to one delegate.