To hide UITabbar
of UITabbarController
which contains UINavigationController
with UITableViewController
in stack one should use hidesBarsOnSwipe
property and add custom selector for barHideOnSwipeGestureRecognizer
:
@implementation SomeTableViewController
- (void)willMoveToParentViewController:(UIViewController *)parent
{
if (parent) {
self.navigationController.hidesBarsOnSwipe = YES;
[self.navigationController.barHideOnSwipeGestureRecognizer addTarget:self action:@selector(swipe:)];
}
else {
self.navigationController.hidesBarsOnSwipe = NO;
[self.navigationController.barHideOnSwipeGestureRecognizer removeTarget:self action:@selector(swipe:)];
}
}
- (void)swipe:(UIPanGestureRecognizer *)recognizer
{
UINavigationBar *bar = self.navigationController.navigationBar;
BOOL isHidden = (bar.frame.origin.y < 0);
[self.tabBarController.tabBar setHidden:isHidden];
[[UIApplication sharedApplication] setStatusBarHidden:isHidden withAnimation:UIStatusBarAnimationSlide];
}
In this way one can hide both tabbar and statusBar. Also one can add some animation effects for hiding/revealing these bars.
It is very important to remove selector before self
has been deallocated. Otherwise, you will get guaranteed crash on the next use of barHideOnSwipeGestureRecognizer
with self.navigationController
.
Note this approach is admissible only for iOS8+.