hidesBottomBarWhenPushed 永远隐藏 TabBar

hidesBottomBarWhenPushed hides TabBar forever

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

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

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

我尝试了几种方法在返回 FirstViewController 时将 hidesBottomBarWhenPushed 设置为 false,但是 none 的尝试成功了。

如何在弹出回 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 外部将 hidesBottomBarWhenPushed 设置为 true。

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

class FirstViewController {

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