HidesBarsOnSwipe with UITabBar

I recently switched to use UITabBarControllerin my application and was not surprised to see that I can not get hidesBarsOnSwipeto work with it. I just say (inside the view controller) hidesBarsOnSwipe = true, but now it does not work. If someone can help me do this work, it will be great.

Thank!

+4
source share
4 answers

I solved the problem. I embedded it UITabBarControllerinside UINavigationController, which I set as the root view controller for the window. After I created the root of only the tab bar controller, it worked like a charm.

Thank!

+1
source

hideOnSwipe,

[self.navigationController.barHideOnSwipeGestureRecognizer addTarget:self action:@selector(swipeGesture:)];

, swipeGesture. / .

+3

in swift3

  self.navigationController?.barHideOnSwipeGestureRecognizer.addTarget(self, action: "swipeGestuere")  

declare a hidden variable that helps return the tab bar

 func swipeGestuere() {
    if (hidden == true){         
    self.bottomTabBar.isHidden = true
        hidden = false
    }
    else{
        self.bottomTabBar.isHidden = false
        hidden = true
    }

}                             
0
source

I decided to resize this UITabBarControllerto get the tab bar off-screen:

- (void)setTabBarHidden:(BOOL)hidden
{
    CGRect frame = self.originalViewFrame;
    if (hidden)
    {
        frame.size.height += self.tabBar.size.height;
    }
    self.view.frame = frame;
}

Then you can add KVO to your scroll view:

[scrollView addObserver:self
             forKeyPath:@"contentOffset"
                options:NSKeyValueObservingOptionOld
                context:nil];

And hide / show scroll tab bar:

- (void)observeValueForKeyPath:(NSString *)keyPath
                      ofObject:(id)object
                        change:(NSDictionary *)change
                       context:(void *)context
{
    CGPoint oldOffset = [(NSValue *)change[NSKeyValueChangeOldKey] CGPointValue];

    if (!_hidesBarsOnScroll || _scrollView.contentOffset.y == oldOffset.y)
        return;

    // Show on scroll up
    if (_barsHidden &&
        scrollView.contentOffset.y < oldOffset.y &&
        scrollView.contentOffset.y + scrollView.bounds.size.height < scrollView.contentSize.height) // Skip on bottom
    {
        [self.navigationController setNavigationBarHidden:NO
                                                 animated:YES]; // Also navigation bar!
        [self.tabBarController setTabBarHidden:NO
                                      animated:YES];
        _barsHidden = NO;
    }

    // Hide on scroll down
    if (!_barsHidden &&
        scrollView.contentOffset.y > 0 && // Skip on top
        scrollView.contentOffset.y > oldOffset.y)
    {
        [self.navigationController setNavigationBarHidden:YES
                                                 animated:YES];
        [self.tabBarController setTabBarHidden:YES
                                      animated:YES];
        _barsHidden = YES;
    }
}

You can take a look at this implementation here .

-1
source

All Articles