首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >hidesBottomBarWhenPushed永远隐藏TabBar

hidesBottomBarWhenPushed永远隐藏TabBar
EN

Stack Overflow用户
提问于 2020-02-23 19:34:40
回答 1查看 146关注 0票数 1

我使用的是Xcode11.2,项目的最低iOS部署目标是iOS 12.4。

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

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

当移回FirstViewController时,我尝试了几种方法将hidesBottomBarWhenPushed设置为false,但都不起作用。

如何在弹出到FirstViewController时重新显示选项卡栏?

代码语言:javascript
复制
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
    }
}
代码语言:javascript
复制
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
    }
}
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2020-02-25 21:10:33

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

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

代码语言:javascript
复制
class FirstViewController {

    func pushSecondViewController {
        let vc = SecondViewController()
        vc.hidesBottomBarWhenPushed = true // <- Here
        navigationController?.push
        navigationController?.pushViewController(vc, animated: true)
    }
}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/60361767

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档