ios - hidesBottomBarWhenPushed 永远隐藏 TabBar
问题描述
我使用 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 外部将 hidesBottomBarWhenPushed 设置为 true。
下面的代码就是我需要编写的全部内容。
class FirstViewController {
func pushSecondViewController {
let vc = SecondViewController()
vc.hidesBottomBarWhenPushed = true // <- Here
navigationController?.push
navigationController?.pushViewController(vc, animated: true)
}
}
推荐阅读
- javascript - 如何识别父页面是从 iframe 中留下的?
- android-studio - webview的单元测试
- c++ - C ++实现具有嵌套结构的类函数
- java - 麻烦,实现main方法的Driver类
- excel - 更新值:输出消息
- tomcat - Tomcat 7:从我没有打包的战争中排除一个 jar
- python - django创建abstractbaseuser模型,错误
- ruby-on-rails - 在 Rails erb 文件中创建实例或局部变量?
- javascript - Python - 通过 javascript 写入 HTML 输入元素
- mongodb - Mongodb findoneandupdate 与聚合管道