Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Hide tab bar in IOS swift app

Tags:

ios

swift

I'm trying to figure out how to hide the tab bar in my iOS swift app. I don't care about any fancy animations or anything. Just something I can put in the ViewDidLoad() function.

like image 511
Robert Avatar asked Feb 28 '15 03:02

Robert


People also ask

How do I hide a tab bar in Swift?

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 a tab view?

Right click on the tab you want to hide. Select Hide.

How do I hide the bottom navigation bar in Swift?

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.


2 Answers

You can simply use this in your ViewDidLoad() method.

self.tabBarController?.tabBar.hidden = true 

For Swift 3.0, 4.0, 5.0:

self.tabBarController?.tabBar.isHidden = true 

Or you can change z position of tab bar this way:

self.tabBarController?.tabBar.layer.zPosition = -1 

and if you want to show it again then:

self.tabBarController?.tabBar.layer.zPosition = 0 
like image 196
Dharmesh Kheni Avatar answered Sep 27 '22 20:09

Dharmesh Kheni


The accepted answer works, but the transition to other view has a choppy animation (The tab Bar animation)

Also wanted to add although Kalpesh's solution worked perfectly for me, I found out that every view controller has an attribute for hidesBottomBarWhenPushed (check out storyboard.) If you wish to hide tab bar, you should put a tick on that. And it would work great.

enter image description here

Update: Im not sure if this is a known thing, but here's what apple documentation page says:

A view controller added as a child of a navigation controller can display an optional toolbar at the bottom of the screen. The value of this property on the topmost view controller determines whether the toolbar is visible. If the value of this property is true, the toolbar is hidden. If the value of this property is false, the bar is visible.

I think this means that you have to set the basic value of hidesBottomBarWhenPushed at the topmost view controller (the first one on the navigation stack.) Once you have set that to true, you can change to false or true for the other viewcontrollers on the stack. But, if your topmost view controller's hidesBottomBarWhenPushed value is false, it will not show a tab bar for other controllers on the navigation stack.

like image 24
Akshansh Thakur Avatar answered Sep 27 '22 19:09

Akshansh Thakur