Search code examples
iosobjective-cuinavigationcontrolleruinavigationbaruinavigationitem

Managing a transition from a normal NavigationBar to a transparent one


I need to manage the transition between two ViewControllers embedded in a NavigationController that uses the standard, light, blurred layer. All of the ViewControllers in this part of the app looks really good with this blurred layer except for one whereas I want it to fade over to become a completely transparent bar and go back to normal when I pop this ViewController.

Desired behaviour:

enter image description here

I've looked into this a long time but I can't figure out how to accomplish it. Can anyone help me with it? I've looked into this question but I don't quite understand how to implement it.

Thank you!


Solution

  • Have you looked into UIViewControllerTransitionCoordinator?

    Each UIViewController has a transitionCoordinator property you can access to perform tasks that are related to a transition.

    From the viewWillAppear/viewWillDisappear methods of the UIViewController doing the transition call the animateAlongsideTransition method of the transitionCoordinator:

    id <UIViewControllerTransitionCoordinator> coordinator = [self transitionCoordinator];
    
    [coordinator animateAlongsideTransition:^(id<UIViewControllerTransitionCoordinatorContext> context) {
        // animate the changes in the navigation bar here
    } completion:nil];