我使用Xcode 11.2,项目的最低iOS部署目标是iOS 12.4。
我在根页面上有一个TabBarController,在其中一个标签上有FirstViewController。当我从FirstViewController推送SecondViewController时,我希望标签栏被隐藏。我使用了hidesBottomBarWhenPushed属性来隐藏选项卡栏。
当我按下SecondViewController时,标签栏被隐藏,但是当我弹出SecondViewController并移回FirstViewController时,标签栏仍然被隐藏。
[我尝试了几种方法来将hidesBottomBarWhenPushed设置为false,当移回FirstViewController时,所有尝试均无效。
弹出到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)
}
}