You have to set that property for the view controller that is pushed. It is important to notice that setting it in viewDidLoad
is too late. You should set in when the view controller instance is initialized instead:
class PushedVC: UIViewController {
required init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
sharedInit()
}
override init(nibName nibNameOrNil: String?, bundle nibBundleOrNil: Bundle?) {
super.init(nibName: nibNameOrNil, bundle: nibBundleOrNil)
sharedInit()
}
private func sharedInit() {
hidesBottomBarWhenPushed = true
}
}
Of course you could also just check the checkmark Hide Bottom Bar on Push
for the specific view controller when using storyboards.
To make sure that your center button gets hidden / shown with the tab bar in this approach you have to add it as a subview of the tab bar in your UITabBar
subclass. Then you override hitTest
to make it fully tappable (of course that is only needed if the button exceeds the tab bar's frame):
class TabBar: UITabBar {
let centerButton = ...
// ...
override func hitTest(_ point: CGPoint, with event: UIEvent?) -> UIView? {
if centerButton.frame.contains(point) {
return centerButton
}
return super.hitTest(point, with: event)
}
// ...
}