ios - 返回UINavigationController时如何隐藏UITabBar
问题描述
我有三个视图控制器:
- FeedController(
UITabBar
可见) - PostController(
UITabBar
隐藏) - 用户控制器(
UITabBar
可见
我使用以下代码执行此操作,从 FeedController 到 PostController:
let postVC = PostController()
postVC.hidesBottomBarWhenPushed = true
pushViewController(postVC, animated: true)
postVC.hidesBottomBarWhenPushed = false
然后,从 PostVC 到 UserVC:
let userVC = UserController()
userVC.hidesBottomBarWhenPushed = false
pushViewController(userVC, animated: true)
它工作得很好。它显示UITabBar
除了导航到帖子之外的任何地方。但是,当我从帖子中转到用户配置文件 (UserController) 时,就会出现问题。它UITabBar
按预期显示在配置文件上,但是当我向后导航(使用我的后退按钮UINavigationController
)时,UITabBar
它仍然可见。当我从 userVC 返回 postVC 时,我希望它再次被隐藏。
有什么办法可以做到这一点吗?
解决方案
在您的帖子视图控制器中尝试:
override func viewWillDisappear(_ animated: Bool) {
postVC.hidesBottomBarWhenPushed = true
}
这将在视图即将消失时调用它,但在它出现时不会调用它,因此当您返回时它应该隐藏。
推荐阅读
- kibana - 带有 Haproxy 的 Kibana 重定向到 https://0.0.0.0
- python - 随机旋转函数张量流
- gitlab-ci - 尝试使用 OpenShift 4 和自我管理的 GitLab 连续安装
- vhdl - 使用 VHSIC 硬件描述语言的计数器
- python - 当我根据值向每个条形添加自定义颜色时,短线条形图会更改 x 轴
- django - 在 Django 中使用 REST 框架发布具有字典属性的非持久模型
- mysql - 将教义与多个 MySQL 数据库一起使用
- javascript - 使用基于 json 文件的值检查输入值
- java - Gradle 7.0 迁移:如何从 compileClasspath 中删除 JAR
- r - 仅对列表中的数字部分求和