Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to hide/show tab bar of a view with a navigation bar in iOS?

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.

like image 556
dork Avatar asked Jun 17 '11 08:06

dork


People also ask

How do I hide the tab bar in IOS?

Simply, Go to ViewController (in StoryBoard) -> Attribute inspector -> Under 'View Controller' section select 'Hide Bottom Bar on Push' checkbox. This works like a charm.

How do you hide the tab bar when a view controller is shown?

If you don't want that behavior, you should set hidesBottomBarWhenPushed to true where applicable. This will hide the tab bar along with any toolbars you had showing, but only when a view controller is pushed onto the navigation stack. This allows you to show the tab bar at first, then hide it when you need more room.

How do I hide the navigation tab?

Way 1: Touch “Settings” -> “Display” -> “Navigation bar” -> “Buttons” -> “Button layout”. Choose the pattern in “Hide navigation bar” -> When the app opens, the navigation bar will be automatically hidden and you can swipe up from the bottom corner of the screen to show it.

Where is tab bar in IOS?

The Tab Bar is the instance of the UITabBar class, which inherits UIView. The tab bar always appears across the bottom edge of the screen.


2 Answers

You can set the UIViewController.hidesBottomBarWhenPushed instead:

DetailViewController *detailViewController = [[DetailViewController alloc] init]; detailViewController.hidesBottomBarWhenPushed = YES; [[self navigationController] pushViewController:detailViewController animated:YES];     [detailViewController release]; 
like image 52
ushika Avatar answered Sep 19 '22 08:09

ushika


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

like image 42
Suragch Avatar answered Sep 23 '22 08:09

Suragch