当 tabbarcontroller-viewcontroller 嵌入导航控制器时,hidesBottomBarWhenPushed 不起作用

hidesBottomBarWhenPushed is not working when tabbarcontroller-viewcontroller's are embedded in navigation controller

我的应用 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)
}

Tabbar 仍然显示在新Vc

要在新 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的view controller中使用这个方法

override var hidesBottomBarWhenPushed: Bool {
    get {
        return navigationController?.topViewController == self
    }
    set {
        super.hidesBottomBarWhenPushed = newValue
    }
}