hidesBottomBarWhenPushed 永远隐藏 TabBar

Posted

技术标签:

【中文标题】hidesBottomBarWhenPushed 永远隐藏 TabBar【英文标题】:hidesBottomBarWhenPushed hides TabBar forever 【发布时间】:2020-02-23 11:34:39 【问题描述】:

我使用 Xcode 11.2,项目最低 ios 部署目标是 iOS 12.4。

我在根页面上有一个 TabBarController,在其中一个标签上我有 FirstViewController。当我从 FirstViewController 推送 SecondViewController 时,我希望隐藏标签栏。我使用 hidesBottomBarWhenPushed 属性来隐藏标签栏。

当我按下 SecondViewController 时标签栏是隐藏的,但是当我弹出 SecondViewController 并移回 FirstViewController 时,标签栏仍然是隐藏的。

当返回 FirstViewController 时,我尝试了多种方法将 hidesBottomBarWhenPushed 设置为 false,但均未奏效。

弹回FirstViewController时如何重新显示标签栏?

class FirstViewController: UIViewController 

    @IBAction func buttonTap(_ sender: Any) 
        let vc2 = SecondViewController()

        // Set to Hide TabBar
        hidesBottomBarWhenPushed = true

        navigationController?.pushViewController(vc2, animated: true)
    

    override func viewWillAppear(_ animated: Bool) 
        super.viewWillAppear(animated)

        // This Does Not Work
        hidesBottomBarWhenPushed = false
    



class SecondViewController: UIViewController 

    /*
        All The Followings Does Not Work
    */

    override func viewWillDisappear(_ animated: Bool) 
        super.viewWillDisappear(animated)

        hidesBottomBarWhenPushed = false
    

    override func viewDidAppear(_ animated: Bool) 
        super.viewDidAppear(animated)

        hidesBottomBarWhenPushed = false
    

    override func viewDidDisappear(_ animated: Bool) 
        super.viewDidDisappear(animated)

        hidesBottomBarWhenPushed = false
    

【问题讨论】:

请检查弹出 secondViewController 您的标签栏是否隐藏。如果隐藏添加 self.tabBarController.tabBar.hidden = false 在 firsrViewController viewWillAppear 函数中添加这一行 【参考方案1】:

关键是从 SecondViewController 外部将 hidesBottomBarWhenPushed 设置为 true。

下面的代码就是我需要编写的全部内容。

class FirstViewController 

    func pushSecondViewController 
        let vc = SecondViewController()
        vc.hidesBottomBarWhenPushed = true // <- Here
        navigationController?.push
        navigationController?.pushViewController(vc, animated: true)
    

【讨论】:

以上是关于hidesBottomBarWhenPushed 永远隐藏 TabBar的主要内容,如果未能解决你的问题,请参考以下文章

使用 hidesBottomBarWhenPushed 在 pop 上显示标签栏

为啥使用半透明导航栏刹车推动动画将“hidesBottomBarWhenPushed”设置为 YES?

hidesBottomBarWhenPushed 永远隐藏 TabBar

如何使用 iOS 6 SDK 解决 hidesBottomBarWhenPushed 的奇怪行为?

当 hidesBottomBarWhenPushed = YES 状态恢复时,导航控制器不隐藏标签栏

带有 UINavigationController 的 UITabBarController,在 hidesBottomBarWhenPushed 上隐藏 UINavigationController