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

问题描述 投票:0回答:3

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

我面临的问题是 hidesBottomBarWhenPushed 当我尝试在单击按钮时从 1st Vc 推送新控制器时无法正常工作

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

Tabbar 仍然显示在 NewVc 中

swift uinavigationcontroller uitabbarcontroller pushviewcontroller
3个回答
1
投票

//在你想隐藏tabBar的view controller中使用这个方法

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

0
投票

要在新 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 在 developer.apple.com/documentation


0
投票

在你的 navigationbar.swift 中添加这些代码

 override func pushViewController(_ viewController: UIViewController, animated: Bool) {
        if children.count > 0 {
            viewController.hidesBottomBarWhenPushed = true
        }
        super.pushViewController(viewController, animated: animated)
    }
© www.soinside.com 2019 - 2024. All rights reserved.