60

I have views with a navigation bar and a tab bar. What I would like to happen is to hide the tab bar on a certain view and show the tab bar again when the user changes views.

I saw a snippet of code for hiding the tab bar:

-(void)makeTabBarHidden:(BOOL)hide
{
    // Custom code to hide TabBar
    if ( [tabBarController.view.subviews count] < 2 ) {
        return;
    }

    UIView *contentView;

    if ( [[tabBarController.view.subviews objectAtIndex:0] isKindOfClass:[UITabBar class]] ) {
        contentView = [tabBarController.view.subviews objectAtIndex:1];
    } else {
        contentView = [tabBarController.view.subviews objectAtIndex:0];
    }

    if (hide) {
        contentView.frame = tabBarController.view.bounds;       
    }
    else {
        contentView.frame = CGRectMake(tabBarController.view.bounds.origin.x,
             tabBarController.view.bounds.origin.y,
             tabBarController.view.bounds.size.width,
             tabBarController.view.bounds.size.height - tabBarController.tabBar.frame.size.height);
    }

    tabBarController.tabBar.hidden = hide;
}

from: http://nickwaynik.com/iphone/hide-tabbar-in-an-ios-app/

I call this on the view wherein I want the tab bar hidden

[self makeTabBarHidden:YES];

it works fine when i show/hide it on that view but when I navigate back to the previous view, the tab bar there is also hidden. I tried calling that function in the view's viewDidUnload, viewWillDisappear, viewDidDisappear functions but nothing happens. The same is true when the function is called in the previous view's viewDidLoad, viewWillAppear, viewDidAppear functions.

Rishil Patel
  • 1,977
  • 3
  • 14
  • 30
dork
  • 4,396
  • 2
  • 28
  • 56

8 Answers8

147

You can set the UIViewController.hidesBottomBarWhenPushed instead:

DetailViewController *detailViewController = [[DetailViewController alloc] init];
detailViewController.hidesBottomBarWhenPushed = YES;
[[self navigationController] pushViewController:detailViewController animated:YES];    
[detailViewController release];
ushika
  • 1,521
  • 1
  • 11
  • 4
  • 3
    Here's a cool looking solution in the case where pushing a new controller isn't an option, that should animate the bar in and out: http://stackoverflow.com/questions/5272290/how-to-hide-uitabbarcontroller/11490623#11490623 – qix Aug 06 '12 at 21:18
  • That was great. Thank you so much. Just to let you know you could do that in prepareForSegue as well. – Roozbeh Zabihollahi Jan 27 '14 at 17:39
  • 1
    One thing to note is that the location of the set is important. Setting `hidesBottomBarWhenPushed` in the location as shown in the answer works, but if setting it within DetailViewController's `viewDidLoad` method doesn't. – CodeBrew Apr 18 '17 at 14:47
36

You can also do this in the Interface Builder for a storyboard. Select the View Controller that you want to hide the Tab Bar for and then select "Hide Bottom Bar on Push".

enter image description here

Suragch
  • 484,302
  • 314
  • 1,365
  • 1,393
13

I just created a category on UITabBarController that allows you to hide the TabBar, optionally with an animation:

https://github.com/idevsoftware/Cocoa-Touch-Additions/tree/master/UITabBarController_setHidden

It adds the tabBarHidden property (with isTabBarHidden as its getter) and the - (void)setTabBarHidden:(BOOL)hidden animated:(BOOL)animated method.

MMiroslav
  • 1,672
  • 20
  • 32
boliva
  • 5,604
  • 6
  • 37
  • 39
  • Would be awesome if the landscape mode fix could get itself checked in. Maybe send a pull request with it, @boliva? – mharper May 22 '13 at 23:49
2

Swift 3: Set tab bar to hide in viewWillAppear or viewDidAppear

self.tabBarController?.tabBar.isHidden = true
shim
  • 9,289
  • 12
  • 69
  • 108
Sandu
  • 436
  • 4
  • 8
2

Try this for hide / show:

- (void)viewWillDisappear:(BOOL)animated {
    self.hidesBottomBarWhenPushed = NO;
}

- (void)viewWillAppear:(BOOL)animated {
    self.hidesBottomBarWhenPushed = YES;
}
shim
  • 9,289
  • 12
  • 69
  • 108
ali ozkara
  • 5,425
  • 2
  • 27
  • 24
1
self.navigationController.hidesBottomBarWhenPushed=YES;

Add this line to your viewDidLoad or viewWillAppear; this will hide you tab from bottom.

shim
  • 9,289
  • 12
  • 69
  • 108
Yogesh Dalavi
  • 73
  • 4
  • 15
0

The same property is available on the attributes inspector when you click on your view controller on your Xib or storyboard file.

ShowPony
  • 162
  • 1
  • 4
0

you can use below code but tabBar remains hidden when you navigate back.

    //hide tabbar
    //self.tabBarController?.tabBar.isHidden = true

better way is to do through main.storyboard check "Hide Bottom Bar on Push" as I've done.

enter image description here

Soropromo
  • 1,212
  • 12
  • 17