Swift version: 5.10
If you’re using UITabBarController
to display a tab strip at the bottom of your user interface, the default behavior for iOS is to display the tabs at all times – even if the user has navigated deep into a UINavigationController
in one of the tabs.
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.
If you’re using segues, the best place to set this property is inside the prepare(for:)
method, where you configure any other properties in your destination view controller:
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
self.hidesBottomBarWhenPushed = true
}
If you aren’t using segues, you will usually need to override the initializer for your view controller and set hidesBottomBarWhenPushed
to true there, like this:
override init(nibName nibNameOrNil: String?, bundle nibBundleOrNil: Bundle?) {
super.init(nibName: nibNameOrNil, bundle: nibBundleOrNil)
hidesBottomBarWhenPushed = true
}
SPONSORED Debug 10x faster with Proxyman. Your ultimate tool to capture HTTPs requests/ responses, natively built for iPhone and macOS. You’d be surprised how much you can learn about any system by watching what it does over the network.
Sponsor Hacking with Swift and reach the world's largest Swift community!
Available from iOS 5.0
This is part of the Swift Knowledge Base, a free, searchable collection of solutions for common iOS questions.
Link copied to your pasteboard.