问题描述
我的应用程序 ui 层次结构如图所示。 UItabbarcontroller -> 导航控制器 -> 视图控制器。
我面临的问题是 hidesBottomBarWhenPushed 在我尝试从第一个 Vc 按下按钮时推送新控制器时不起作用
if let newVc = UIStoryboard.homeSB.instantiateViewController(withIdentifier: NewViewController.identifier()) as? NewViewController{
self.navigationController?.hidesBottomBarWhenPushed = true
self.navigationController?.pushViewController(viewAllVc,animated: true)
}
解决方法
要在新的 VC 中隐藏标签栏,您可以在 viewDidLoad() 中调用它:
self.tabBarController?.tabBar.isHidden = true
此外,您应该从 VC 调用方法 hidesBottomBarWhenPushed,而不是从导航控制器:
if let newVc = UIStoryboard.homeSB.instantiateViewController(withIdentifier: NewViewController.identifier()) as? NewViewController{
newVc.hidesBottomBarWhenPushed = true
self.navigationController?.pushViewController(viewAllVc,animated: true)
}
此外,您还可以将其添加到新的 VC 故事板中:
hidesBottomBarWhenPushed in developer.apple.com/documentation
,//在你想隐藏tabBar的视图控制器中使用这个方法
override var hidesBottomBarWhenPushed: Bool {
get {
return navigationController?.topViewController == self
}
set {
super.hidesBottomBarWhenPushed = newValue
}
}