Swift

How To Hide The Tab Bar When Showing A New View Controller

Sometimes, when using a UITabBarController, you want to push a new view controller without the tab bar. Unfortunately, the default behaviour for a UITabBarController is to show the tab bar no matter how many view controllers have been pushed.

Luckily, there is an easy way to elegantly hide the tab bar using the hidesBottomBarWhenPushed property that every view controller has.

Example Using Code

func moveToNextViewController() {
    let vc = MyViewController()
    vc.hidesBottomBarWhenPushed = true
    navigationController?.pushViewController(vc, animated: true)
}

Example Using Segues

override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
    self.hidesBottomBarWhenPushed = true
}



Thanks for reading, see you in the next article.