40

In my app I have a tab bar. And in some views I as well have a toolbar. So when I come to those views with a toolbar it looks ugly - two bars at the bottom of the view. I thought that it would be a best solution to hide a tab bar when entering those particular views. But I just couldn't figure out how to do it in a right way. I tried to set UITabBarController's tabBar hidden property to YES, but it didn't work. And I as well tried to do the following thing in whatever view I am:

self.hidesBottomBarWhenPushed = YES;

But it didn't work as well.

What is the right solution to this situation? I don't want to have 2 bars at any view.

Cœur
  • 37,241
  • 25
  • 195
  • 267
Ilya Suzdalnitski
  • 52,598
  • 51
  • 134
  • 168

5 Answers5

68

You have to use set the hidesBottomBarWhenPushed property to YES on the controller that you are pushing and NOT to the UITabBarController.

otherController.hidesBottomBarWhenPushed = YES;
[navigationController pushViewController: otherController animated: TRUE];

Or you can set the property when you first initialize the controller you want to push.

Panagiotis Korros
  • 10,840
  • 12
  • 41
  • 43
  • 1
    I have three view controllers that the UITabBarController can present. On the second view controller, I put `self.hidesBottomBarWhenPushed = YES` in `initWithNibName:bundle:`. When I tested tapping into the second view controller, the UITabBar was still there. – JoJo Sep 27 '11 at 22:10
  • 1
    Tried on a new project with ios7 - no effect – Adam Jan 02 '14 at 12:40
  • When I go back to the screen, I have a black space on top of the tab bar. – manonthemoon May 28 '16 at 08:41
13

Interface builder has checkbox for view controller embedded in tab bar - Hides bottom bar on push. In easy cases no need to do it through code now.

For @Micah

Hide bottom bar on push.

Vladimir Shutyuk
  • 2,956
  • 1
  • 24
  • 26
9

I too struggled with this for a while. Hiding the tab bar is one step in the right direction, but leaves a black rectangle behind. The trick is to resize the layer that backs the UIViewController's view.

I have written a small demo here with a solution:

https://github.com/tciuro/FullScreenWithTabBar

I hope this helps!

titusmagnus
  • 2,014
  • 3
  • 23
  • 23
  • Awesome tip, wish I could upvote more. I didn't even know there WAS a layer backing the UIViewController! – ryan0 Nov 05 '13 at 15:31
9

Don't use this solution!

BOOL hiddenTabBar;
UITabBarController *tabBarController;

- (void) hideTabBar {

     [UIView beginAnimations:nil context:NULL];
     [UIView setAnimationDuration:0.4];
     for(UIView *view in tabBarController.view.subviews)
     {
          CGRect _rect = view.frame;
          if([view isKindOfClass:[UITabBar class]])
          {
               if (hiddenTabBar) {
                    _rect.origin.y = [[UIScreen mainScreen] bounds].size.height-49;
                    [view setFrame:_rect];
               } else {
                    _rect.origin.y = [[UIScreen mainScreen] bounds].size.height;
                    [view setFrame:_rect];
               }
          } else {
               if (hiddenTabBar) {
                    _rect.size.height = [[UIScreen mainScreen] bounds].size.height-49;
                    [view setFrame:_rect];
               } else {
                    _rect.size.height = [[UIScreen mainScreen] bounds].size.height;
                    [view setFrame:_rect];
               }
          }
     }    
     [UIView commitAnimations];

     hiddenTabBar = !hiddenTabBar;
}

Source

Volodymyr B.
  • 3,369
  • 2
  • 30
  • 48
  • 1
    Using a custom tab bar (ALTabBar). This one worked for me. Instead to support 4" screen, I have changed 480 to [[UIScreen mainScreen] bounds] -> size.height – Uygar Y Oct 26 '13 at 10:16
  • 1
    great, but... try not use fixed values like 431 or 480. You should always write code to run in any screen size! – orafaelreis Aug 10 '14 at 16:17
  • If you want really resize the view (not only hide tabBar) set self.tabBarController.tabBar.hidden = hiddenTabBar; – orafaelreis Aug 15 '14 at 16:23
0

There is no built in way to hide the tab bar for your current view.

You can hide it when pushing a view with the hidesBottomBarWhenPushed variable.

If you want to hide your tab bar on your current view, you can do the following:

Gist here

Note that UIKit seems to bring the tab bar to come back on app resume. So you will have to subscribe to the notification UIApplication.didBecomeActiveNotification and call the above function.

Xaxxus
  • 1,083
  • 12
  • 19