How to hide / show tab bar using navigation bar in iOS?

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

I saw a code snippet to hide 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 in a view in which I want the tab bar to be hidden

 [self makeTabBarHidden:YES]; 

It works great when I show / hide it in this view, but when I go back to the previous view, the tab bar is also hidden. I tried calling this function in the view viewDidUnload, viewWillDisappear, viewDidDisappear, but nothing happens. The same is true when a function is called in the previous view viewDidLoad, viewWillAppear, viewDidAppear function.

+54
ios uitabbarcontroller uinavigationcontroller
Jun 17 '11 at 8:12
source share
7 answers

Instead, you can set UIViewController.hidesBottomBarWhenPushed:

 DetailViewController *detailViewController = [[DetailViewController alloc] init]; detailViewController.hidesBottomBarWhenPushed = YES; [[self navigationController] pushViewController:detailViewController animated:YES]; [detailViewController release]; 
+138
Sep 23 2018-11-11T00:
source share

You can also do this in the storyboard interface builder. Select the view controller that you want to hide the tab bar, and then select "Hide the bottom bar when pressed."

enter image description here

+28
Oct 29 '15 at 10:26
source share

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

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

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

+13
Feb 04 2018-12-12T00:
source share
 self.navigationController.hidesBottomBarWhenPushed=YES; 

Add this line to viewdidload or viewWillAppear this will hide your tab at the bottom.

+2
Dec 22 '16 at 5:52
source share

Swift 3: Set panel hiding in viewwillAppear or viewdidappear

 self.tabBarController?.tabBar.isHidden = true 
+1
Apr 24 '17 at 7:44
source share

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

0
Nov 22 '14 at 20:58
source share

try this for hide / show;

 -(void)viewWillDisappear:(BOOL)animated{ self.hidesBottomBarWhenPushed = NO; } -(void)viewWillAppear:(BOOL)animated{ self.hidesBottomBarWhenPushed = YES; } 
0
Nov 08 '17 at 8:37
source share



All Articles