The accepted answer had a problem to me.
My app had a navigation with the depth of three UIViewController.
- The FirsViewController show's the UITabBar. (Correct)
- The FirsViewController pushes the SecondViewController, and the SecondViewController don't show's the UITabBar. (Correct)
- The SecondViewController pushed the ThirdViewController, and the ThirdViewController show's the UITabBar. (Incorrect)
- The ThirdViewController popped to the SecondViewController, and the SecondViewController show's the UITabBar. (Incorrect)
- The SecondViewController popped to the FirstViewController, and the FirstViewController show's the UITabBar. (Correct)
The solution for me was setting the delegate of UINavigationControllerDelegate
swift:
self.navigationController?.delegate = self
Objective-c:
self.navigationController.delegate = self;
And then implement the following delegate method
Swift:
fun navigationController(navigationController: UINavigationController, animationControllerForOperation operation: UINavigationControllerOperation, fromViewController fromVC: UIViewController, toViewController toVC: UIViewController) -> UIViewControllerAnimatedTransitioning? {
if fromVC.isKindOfClass(FirstViewController) && toVC.isKindOfClass(SecondViewController) {
self.hidesBottomBarWhenPushed = true;
}
else if fromVC.isKindOfClass(SecondViewController) && toVC.isKindOfClass(FirstViewController) {
self.hidesBottomBarWhenPushed = false;
}
return nil
}
Objective-c:
-(id<UIViewControllerAnimatedTransitioning>)navigationController:(UINavigationController *)navigationController
animationControllerForOperation:(UINavigationControllerOperation)operation
fromViewController:(UIViewController*)fromVC
toViewController:(UIViewController*)toVC
{
if ([fromVC isKindOfClass:[FirstViewController class]] && [fromVC isKindOfClass:[SecondViewController class]]) {
self.hidesBottomBarWhenPushed = true;
}
else if ([fromVC isKindOfClass:[SecondViewController class]] && [fromVC isKindOfClass:[FirstViewController class]]) {
self.hidesBottomBarWhenPushed = false;
}
return nil;
}
Hope it helped.