UITableView: shrink panel and scroll up navigation bar

Scenario

I have an application that uses a tab bar controller (at the bottom of the screen) with a navigation controller interface design (at the top of the screen). On one view controller, I have a UITableView with content that the user will “Scroll Up” to scroll through the table to view the content.

Need

Like Yahoo! and the Instagram app, I would like to have a top Nav bar, and the bottom tab bar “shrinks” and “disappears” when the user feels that the user is viewing the View table. And of course, when the user bounces again, I would like them to reappear.

Question

Does anyone know how to do this?

+3
source share
1 answer

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 +.

+1
source

All Articles