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

IosUinavigationcontrollerUitabbarcontroller

Ios Problem Overview


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.

Ios Solutions


Solution 1 - Ios

You can set the UIViewController.hidesBottomBarWhenPushed instead:

DetailViewController *detailViewController = [[DetailViewController alloc] init];
detailViewController.hidesBottomBarWhenPushed = YES;
[[self navigationController] pushViewController:detailViewController animated:YES];    
[detailViewController release];

Solution 2 - Ios

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

Solution 3 - Ios

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.

Solution 4 - Ios

self.navigationController.hidesBottomBarWhenPushed=YES;

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

Solution 5 - Ios

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

self.tabBarController?.tabBar.isHidden = true

Solution 6 - Ios

Try this for hide / show:

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

- (void)viewWillAppear:(BOOL)animated {
    self.hidesBottomBarWhenPushed = YES;
}

Solution 7 - Ios

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

Solution 8 - Ios

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

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestiondorkView Question on Stackoverflow
Solution 1 - IosushikaView Answer on Stackoverflow
Solution 2 - IosSuragchView Answer on Stackoverflow
Solution 3 - IosbolivaView Answer on Stackoverflow
Solution 4 - IosYogesh DalaviView Answer on Stackoverflow
Solution 5 - IosSanduView Answer on Stackoverflow
Solution 6 - IosAli OzkaraView Answer on Stackoverflow
Solution 7 - IosShowPonyView Answer on Stackoverflow
Solution 8 - IosSoropromoView Answer on Stackoverflow