To hide UITabbarof UITabbarControllerwhich contains UINavigationControllerc UITableViewControlleron the stack, use the property hidesBarsOnSwipeand add a 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];
}
This way you can hide both tabs and statusBar. You can also add some animation effects to hide / reveal these bars.
It is very important to remove the selector before it selfis released. Otherwise, you will get a guaranteed failure the next time you use barHideOnSwipeGestureRecognizerc self.navigationController.
Please note that this approach is valid only for iOS8 +.
source
share