swift hidesBottomBarWhenPushed在tabbarcontroller-viewcontroller嵌入导航控制器时不工作

db2dz4w8  于 2023-04-28  发布在  Swift
关注(0)|答案(3)|浏览(108)

我的应用程序用户界面层次结构看起来像如图所示。UItabbarcontroller -〉navigation-controllers -〉view-controllers。

我面临的问题是hidesBottomBarWhenPushed不工作时,我试图推动一个新的控制器从第一VC按钮点击

if let newVc = UIStoryboard.homeSB.instantiateViewController(withIdentifier: NewViewController.identifier()) as? NewViewController{
    self.navigationController?.hidesBottomBarWhenPushed = true
    self.navigationController?.pushViewController(viewAllVc, animated: true)
}

Tabbar仍在NewVc中显示

knsnq2tg

knsnq2tg1#

//在要隐藏tabBar的视图控制器中使用此方法

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

qcbq4gxm2#

要在new 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

vngu2lb8

vngu2lb83#

在导航栏中添加这些代码。雨燕

override func pushViewController(_ viewController: UIViewController, animated: Bool) {
        if children.count > 0 {
            viewController.hidesBottomBarWhenPushed = true
        }
        super.pushViewController(viewController, animated: animated)
    }

相关问题