This is related to another question of mine, iOS 8 + interactive transition + nav bar shown = broken?, but is different.
On iOS 8, when one is doing an interactive transition from view A to view B via the NavigationControllerDelegate
/ UIViewControllerInteractiveTransitioning
method, and view A has a navbar, and view B does NOT, then what is the correct method to hide / unhide the nav bar?
I tried to do this in the ViewController like this:
- (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 (mainly the navbar) "flickers" sometimes when animation is completing. This is really ugly if you have a complex view underneath.
If the user cancels the interactive transition (ie. by not dragging far enough or pinching enough) then the navbar goes away forever, even though I can see in the code that it's being told to unhide.
Here is some soure-code to show this happening: https://github.com/xaphod/UIViewControllerTransitionTut
--> un-pinch to go from one view controller to another; the first view has a nav bar, the second one does not. When you complete the transition, you can sometimes see flickering (problem 1 above). When you un-pinch just a little bit and let go, that's a cancelled transition: although you're still on view 1, the navbar has disappeared (problem 2 above).