What is the correct way to hide / show the navigation bar during an interactive transition through the NavigationControllerDelegate?

This is related to my other question, iOS 8 + interactive transition + navigation bar shown = broken? but different.

In iOS 8, when you make an interactive transition from view A to view B using the NavigationControllerDelegate / UIViewControllerInteractiveTransitioning , and there is a navigation bar in view A and not in view B, what is the correct method to hide / show the navigation bar?

I tried to do this in the ViewController as follows:

 - (void)viewWillAppear:(BOOL)animated { [super viewWillAppear:animated]; [[self transitionCoordinator] animateAlongsideTransition:^(id<UIViewControllerTransitionCoordinatorContext> context) { if (self.navigationController) { [self.navigationController setNavigationBarHidden:YES animated:animated]; } } completion:^(id<UIViewControllerTransitionCoordinatorContext> context) { NSArray *debugViews = [context containerView].subviews; NSLog(@"%@", debugViews); if ([context isCancelled] ) { if( self.navigationController ) { [self.navigationController setNavigationBarHidden:NO animated:animated]; } } }]; } - (void)viewWillDisappear:(BOOL)animated { [[self transitionCoordinator] animateAlongsideTransition:^(id<UIViewControllerTransitionCoordinatorContext> context) { if (self.navigationController) { [self.navigationController setNavigationBarHidden:NO animated:animated]; } } completion:^(id<UIViewControllerTransitionCoordinatorContext> context) { if ([context isCancelled] ) { if( self.navigationController ) { [self.navigationController setNavigationBarHidden:YES animated:animated]; } } }]; [super viewWillDisappear:animated]; } 

... but there are two big problems:

  • The view (mostly navbar) sometimes flickers when the animation completes. This is really ugly if you have a complex view below.

  • If the user cancels the interactive transition (i.e., without dragging enough or without pinching), the navigator leaves forever, although I see in the code what they tell him to show.

Here is some code to show this: https://github.com/xaphod/UIViewControllerTransitionTut

-> un-pinch switch from one view controller to another; the first view has a navigation bar, the second - no. When you complete the transition, you may sometimes see flickering (problem 1 above). When you press and release a little, this is the canceled transition: although you are still in view 1, the navigation bar has disappeared (problem 2 above).

+6
source share
2 answers

The correct way to hide the navigation bar would be to use the navigation manager delegate, make sure you set the navigation window manager delegate for yourself before using the following delegate method: -

Just do it in AppDelegate.m

 - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { self.window.rootViewController.navigationController.delegate=self; //do your rest code... } -(void)navigationController:(UINavigationController *)navController willShowViewController:(UIViewController *)viewController animated:(BOOL)animated { [navController setNavigationBarHidden:([viewController isKindOfClass:[CustomViewController class]]) animated:animated]; // just mention the view controller class type for which you want to hide } 

Link to this SFO

+1
source

If you want to hide the navigation bar, in particular the viewcontroller , you can use this method in wilAppear.

 //Unhide -(void)viewWillAppear:(BOOL)animated { self.navigationController.navigationBarHidden = NO; } //Hide -(void)viewWillAppear:(BOOL)animated { self.navigationController.navigationBarHidden = YES; } 
0
source

All Articles