This is an issue that has bugged me for a while, and I only just found a solution that works. The hidesBottomBarWhenPushed
property is a very strange beast, and works in, to my mind, a counter-intuitive way.
The problem with it is that when you push a new view controller (or pop back) the navigationController will ask all view controllers (from top to bottom) if they want to hide the bottom bar, and if any of them say YES
the tabbar will be hidden, which is why the tabbar remains hidden despite setting NO
to hiding on the new view controller.
Here is my solution - override the hidesBottomBarWhenPushed
getter in the view controller that you wish to not have a tabbar, and check if it is at the top of the stack:
Objective-C
- (BOOL) hidesBottomBarWhenPushed
{
return (self.navigationController.topViewController == self);
}
Swift (not so obvious, hence snippet)
override var hidesBottomBarWhenPushed: Bool {
get {
return navigationController?.topViewController == self
}
set {
super.hidesBottomBarWhenPushed = newValue
}
}
This nicely encapsulates the hide/show logic in one place, so you dont have to think about it outside of the viewcontroller that does the hiding.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…