【发布时间】:2020-02-23 11:34:39
【问题描述】:
我使用 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 您的标签栏是否隐藏。如果隐藏添加 self.tabBarController.tabBar.hidden = false 在 firsrViewController viewWillAppear 函数中添加这一行
标签: ios swift uitabbarcontroller uitabbar