4

I recently switched to using a UITabBarController within my app and was not amused to find I could not make hidesBarsOnSwipe work with it. I use to simply say (within the view controller) hidesBarsOnSwipe = true, but now that does not work. If someone could help me make this work, that would be great.

Thanks!

Zoyt
  • 4,809
  • 6
  • 33
  • 45
  • have you tried with `hidesBarsOnSwipe = YES;`? If it doesn't help provide some code for us to investigate. – carlodurso Nov 03 '14 at 00:18
  • @carlodurso - I'm in Swift. – Zoyt Nov 03 '14 at 00:22
  • Try `self.navigationController!.hidesBarsOnSwipe = true`, hidesBarsOnSwipe is only included in NavigationController, it may later be added to UITabBarController, it did worked for me in a case that UITabBarController is the initial controller, and both items are embedded in NavigationController, by adding this code in both items's viewDidLoad method. – gabbler Nov 06 '14 at 08:26
  • @Zout, you can find exact solution [here](http://stackoverflow.com/a/32445701/2066428) – malex Sep 07 '15 at 20:34

4 Answers4

3

You can add action to the hideOnSwipe like below

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

Add what ever code you want in the swipeGesture method. Hide/unhide tab bar.

Pavan Kotesh
  • 143
  • 13
0

I solved the issue. I had embedded the UITabBarController inside a UINavigationController, which I had put as the root view controller for the window. After I made the root just the tab bar controller, it worked like a charm.

Thanks!

Zoyt
  • 4,809
  • 6
  • 33
  • 45
0

in swift3

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

declare a variable hidden which helps to get the tab bar back

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

}                             
Sateesh Pasala
  • 772
  • 8
  • 15
-1

I solved this by resizing the UITabBarController just enough to get the tab bar out of the 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 your scroll view:

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

And hide/show the tab bar on scroll:

- (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 to this implementation here.

Rivera
  • 10,792
  • 3
  • 58
  • 102
  • I need to have the tab bar hide when I swipe up in the scroll view in the UIViewController. – Zoyt Nov 08 '14 at 02:32
  • You just need to call `setTabBarHidden:` on scroll. Added sample code for that as well but you can do it differently if you want. – Rivera Nov 10 '14 at 02:28