'Hide tab bar in IOS swift app

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.



Solution 1:[1]

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 2:[2]

Before push set controller.hidesBottomBarWhenPushed = true

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

Solution 3:[3]

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 4:[4]

Swift 3.

self.tabBarController?.tabBar.isHidden = true

Solution 5:[5]

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 6:[6]

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

tabBarController?.hidesBottomBarWhenPushed = true

or

hidesBottomBarWhenPushed = true

Solution 7:[7]

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 8:[8]

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
}

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1
Solution 2 kalpesh jetani
Solution 3
Solution 4 Ronny K
Solution 5 Yair hadad
Solution 6
Solution 7 Alberto
Solution 8 Ten