Hide tab bar in IOS swift app

IosSwift

Ios Problem Overview


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.

Ios Solutions


Solution 1 - Ios

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

Solution 2 - Ios

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.

Solution 3 - Ios

> Before push set controller.hidesBottomBarWhenPushed = true

let objCreateEventVC = CreateEventVC()
objCreateEventVC.hidesBottomBarWhenPushed = true
self.navigationController?.pushViewController(objCreateEventVC, animated: false)

Solution 4 - Ios

No need to set tabBar's isHidden property.

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

If you go the 'isHidden' way you need to do a lot of handling, i.e. to make it appear again when you go back and also to remove the bottom empty space after hiding tabBar.

Solution 5 - Ios

Swift 3.

self.tabBarController?.tabBar.isHidden = true

Solution 6 - Ios

You can also set it in extension (use Dharmesh Kheni answer)

extension UITabBar {
func tabsVisiblty(_ isVisiblty: Bool = true){
    if isVisiblty {
        self.isHidden = false
        self.layer.zPosition = 0
    } else {
        self.isHidden = true
        self.layer.zPosition = -1
    }
}

Solution 7 - Ios

This is the way programmatically for Swift 4.0, 4.1, 4.2, 5.0 and later >:

tabBarController?.hidesBottomBarWhenPushed = true

or

hidesBottomBarWhenPushed = true

Solution 8 - Ios

To hide the navigationBar and the tabBar I use the next function:

var tabBarHeight : CGFloat!

func fullScreenAction(){
	if navigationController?.isNavigationBarHidden ?? false {
        //Show navigationBar
		navigationController?.setNavigationBarHidden(false, animated: false)
 
        //Show tabBar
		tabBarController?.tabBar.isHidden = false
		//Update the height of tabBar
		if (!(tabBarController?.tabBar.frame.size.height.isEqual(to: 0))!) {
			tabBarHeight = self.tabBarController?.tabBar.frame.size.height
		}
		tabBarController?.tabBar.frame.size.height	 = tabBarHeight
	} else {
        //Hide navigationBar
		navigationController?.setNavigationBarHidden(true, animated: false)

        //Hide tabBar
		tabBarController?.tabBar.isHidden = true
        //Update the height of tabBar
        tabBarHeight = tabBarController?.tabBar.frame.size.height
		tabBarController?.tabBar.frame.size.height	 = 0
		
	}
	
}

When the screen orientation has changed the height of tabBar change too, so I use the next function to exit of fullscreen to resize the height:

override func viewWillTransition(to size: CGSize, with coordinator: UIViewControllerTransitionCoordinator) {
	super.viewWillTransition(to: size, with: coordinator)
	if navigationController?.isNavigationBarHidden ?? false {
		navigationController?.setNavigationBarHidden(false, animated: false)
		tabBarController?.tabBar.isHidden = false
	}
}

I hope it is useful for you.

Solution 9 - Ios

Here is my code. it's just to hide its tabbar. (If no frames are well established there will be a black view at the bottom. )

var oldTabbarFr: CGRect = .zero

override func viewDidLoad() {
    super.viewDidLoad()
    // Do any additional setup after loading the view.
    oldTabbarFr = self.tabBarController?.tabBar.frame ?? .zero
}

override func viewWillAppear(_ animated: Bool) {
    super.viewWillAppear(animated)
    self.tabBarController?.tabBar.isHidden = true
    self.tabBarController?.tabBar.frame = .zero
}

override func viewWillDisappear(_ animated: Bool) {
    super.viewWillDisappear(animated)
    self.tabBarController?.tabBar.isHidden = false
    self.tabBarController?.tabBar.frame = oldTabbarFr
}

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
QuestionRobertView Question on Stackoverflow
Solution 1 - IosDharmesh KheniView Answer on Stackoverflow
Solution 2 - IosAkshansh ThakurView Answer on Stackoverflow
Solution 3 - Ioskalpesh jetaniView Answer on Stackoverflow
Solution 4 - IosTejasView Answer on Stackoverflow
Solution 5 - IosRonny KView Answer on Stackoverflow
Solution 6 - IosYair hadadView Answer on Stackoverflow
Solution 7 - IosJ. DoeView Answer on Stackoverflow
Solution 8 - IosAlbertoView Answer on Stackoverflow
Solution 9 - IosTenView Answer on Stackoverflow