我使用的是Xcode11.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
}
}发布于 2020-02-25 21:10:33
关键是从SecondViewController外部将hidesBottomBarWhenPushed设置为true。
下面的代码就是我需要编写的全部代码。
class FirstViewController {
func pushSecondViewController {
let vc = SecondViewController()
vc.hidesBottomBarWhenPushed = true // <- Here
navigationController?.push
navigationController?.pushViewController(vc, animated: true)
}
}https://stackoverflow.com/questions/60361767
复制相似问题