微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

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

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

我的应用程序 ui 层次结构如图所示。 UItabbarcontroller -> 导航控制器 -> 视图控制器。

enter image description here

我面临的问题是 hidesBottomBarWhenPushed 在我尝试从第一个 Vc 按下按钮时推送新控制器时不起作用

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

标签栏仍然显示在 NewVc 中

解决方法

要在新的 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 故事板中:

enter image description here

hidesBottomBarWhenPushed in developer.apple.com/documentation

,

//在你想隐藏tabBar的视图控制器中使用这个方法

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

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。