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).
source share