124

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.

1
  • Set this before pushing the VC. vc.hidesBottomBarWhenPushed = true should do the work. DO NOT manually show and hide the tabbar. Dec 17, 2019 at 7:02

10 Answers 10

260

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
8
  • 21
    Dharmesh, thanks for the reply. This sucessfully hides the tab bar, but then table view does not fill the screen. It's just black where the tab bar should be. I guess there's another step to make it fit the screen?
    – Robert
    Feb 28, 2015 at 14:44
  • 3
    Add constraints for that. Feb 28, 2015 at 14:51
  • 2
    What are the "constraints" to add?
    – db0
    Mar 25, 2016 at 15:16
  • 8
    But the tab bar would still take the touch, try tapping near any tab of invisible tab bar. @DharmeshKheni
    – Shobhit C
    Jan 13, 2017 at 9:32
  • 1
    Leaves a blank space. Better handle from storyboard option Hide bottom bar on push (checkbox).
    – Tejas
    Jul 27, 2022 at 3:51
166

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.

8
  • 2
    that's what we should do. A lot better than other answers if you just want to hide it while you present the ViewController Jul 3, 2016 at 22:39
  • why is this not work in Swift 4?? I already tick the option,but it still appear when I go to that particular view controller
    – ken
    Jan 18, 2018 at 11:02
  • This also hides the tab bar for any view controllers that get added to the stack after this. Is there a way to bring it back for those subsequent view controllers? Feb 2, 2018 at 20:40
  • @JustinVallely Please let me know if update works in the answer Feb 16, 2018 at 8:23
  • 1
    Thanks, the accepted answer had a problem for me, when I go back to the view I was coming from, the Tabbar for that also was dissappeard! May 1, 2018 at 8:07
90

Before push set controller.hidesBottomBarWhenPushed = true

let objCreateEventVC = CreateEventVC()
objCreateEventVC.hidesBottomBarWhenPushed = true
self.navigationController?.pushViewController(objCreateEventVC, animated: false)
1
  • Doesn't work when adding a bunch of controllers with setViewControllers
    – K.R.
    Sep 28, 2020 at 8:30
36

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.

4
  • 3
    This should be the actual answer. This allowed me to set the constraints for my UI elements without any hassle. Dec 23, 2017 at 17:39
  • 3
    Hide Bottom Bar on Push has an unpleasant animation, imo. Aug 9, 2018 at 9:43
  • When you get back from this page, Tabbar freezes a little and comes back. What do you think is the reason?
    – Yunus Tek
    Jan 19, 2019 at 22:43
  • This doesn't work when the app comes from the background. Any idea?
    – Mac_Play
    Jul 26, 2021 at 14:49
6

Hide & Show Tab Bar With Animation

For those looking to hide/show the tab bar with animation.

Since iOS 13, the behavior of the UITabBar has changed for animations. You can no longer use CGAffineTransform and instead you should animate its frame position.

See my full guide here: hide & show tab bar with animation

To hide the tab bar:

UIView.animate(withDuration: 0.7, delay: 0, usingSpringWithDamping: 0.8, initialSpringVelocity: 0.7, options: .curveEaseOut) {
    if let tabBarFrame = self.tabBarController?.tabBar.frame {
        self.tabBarController?.tabBar.frame.origin.y = navigationController.view.frame.maxY + tabBarFrame.height
    }
    navigationController.view.layoutIfNeeded()
} completion: { _ in
    self.tabBarController?.tabBar.isHidden = true
}

To show the tab bar:

UIView.animate(withDuration: 0.7, delay: 0, usingSpringWithDamping: 0.8, initialSpringVelocity: 0.7, options: .curveEaseOut) {
    if let tabBarFrame = self.tabBarController?.tabBar.frame {
        self.tabBarController?.tabBar.frame.origin.y = navigationController.view.frame.maxY - tabBarFrame.height
    }
    navigationController.view.layoutIfNeeded()
}

Make sure to call layoutIfNeeded() inside the UIView.animate to trigger the changes with animation.

2
  • This is great, but how do you get the content above the tabBar to reclaim the empty space? May 30 at 5:14
  • Not sure if I fully understand your question, but depending on how you've set up your navigation stack, normally the content is behind the tab bar (not above) and therefore already occupies the empty space whether the tab bar is hidden or not. Is this what you meant?
    – sbiljeek
    Jun 2 at 6:53
5

Swift 3.

self.tabBarController?.tabBar.isHidden = true
4

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

tabBarController?.hidesBottomBarWhenPushed = true

or

hidesBottomBarWhenPushed = true
9
  • @NicoS. True. Where in the question/answer do you read anything about a tool bar?
    – J. Doe
    Apr 9, 2019 at 6:28
  • From the documentation: A Boolean value indicating whether the toolbar at the bottom of the screen is hidden when the view controller is pushed on to a navigation controller.
    – Nico S.
    Apr 9, 2019 at 17:42
  • 1
    The question is about the TabBar not the ToolBar
    – Nico S.
    Apr 9, 2019 at 17:42
  • 1
    the first one doesn't work, the second one should be added when performing a segue or before pushing the view controller.
    – Gal Shahar
    Sep 22, 2019 at 19:19
  • 1
    thanks for: destinationVC.hidesBottomBarWhenPushed = true. For all other options the bottom bar was gone but a big black hole was there.
    – Guilherme
    Jun 17, 2020 at 14:34
3

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
    }
}
0
2

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
}
1

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.