答案: 在每个视图控制器中使用self.tabBarController?.tabBar.hidden而不是hidesBottomBarWhenPushed来管理视图控制器是否应显示标签栏。
override func viewWillAppear(animated: Bool) {
self.tabBarController?.tabBar.hidden = true/false
}
我想要
查看控制器1:应显示标签栏
查看控制器2:应显示标签栏
查看控制器3:不应显示标签栏。
查看控制器4:不应显示标签栏。
我写了
// prepareForSegue in view controller 1,
let upcoming = segue.destinationViewController as! viewcontroller3
upcoming.hidesBottomBarWhenPushed = true
// in view controller 3,
func clickOnButton(button: UIButton) {
self.hidesBottomBarWhenPushed = false
self.performSegueWithIdentifier("viewController2", sender: self)
self.hidesBottomBarWhenPushed = true
}
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
if segue.identifier == "viewController2" {
let upcoming = segue.destinationViewController as! viewController2
upcoming.hidesBottomBarWhenPushed = false
}
}
// prepareForSegue in view controller 2
let upcoming = segue.destinationViewController as! viewController4
upcoming.hidesBottomBarWhenPushed = true
如果1 - > 3然后回到1,工作。
如果1 - > 3 - > 2然后回到3并回到1,工作。
如果2 - > 4,然后回到2,工作。
如果1 - > 3 - > 2 - > 4然后回到2,标签栏未显示。想知道为什么。任何关于hidesBottomBar的任何建议或一些解释,因为它让我很困惑
答案 0 :(得分:24)
正如它的名字所示,hiddenBottomBarWhenPush只在需要时隐藏底栏,它不会取消隐藏bottomBar。 你可以这样做,让它工作:
override func viewWillAppear(animated: Bool) {
super.viewWillAppear(animated)
self.tabBarController?.tabBar.hidden = true/false
}
或简单地将self.tabBarController?.tabBar.hidden = true/false
放入prepareForSegue
但我不建议你这样做,因为如果bottomBar突然弹出会很奇怪,用户会认为他们突然回到rootViewController而不是。
用户应始终知道他们在您的应用中的位置以及如何到达下一个目的地。
答案 1 :(得分:3)
在ViewController中添加此实现,以便在推/弹出时隐藏/显示标签栏。它也适用于所有下一个推送视图控制器。
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
if wilmove {
hidesBottomBarWhenPushed = true
}
wilmove = false
}
override func viewWillDisappear(_ animated: Bool) {
super.viewWillDisappear(animated)
if wilmove {
hidesBottomBarWhenPushed = false
}
wilmove = false
}
var wilmove = false
override func willMove(toParentViewController parent: UIViewController?) {
super.willMove(toParentViewController: parent)
wilmove = true
if !isViewLoaded {
hidesBottomBarWhenPushed = true
}
}
答案 2 :(得分:1)
将hidesBottomBarWhenPushed属性添加到目标视图控制器,并设置为true。
带有标识符为push VC的示例:
Uncaught TypeError: exists is not a function
at Function.getRoot (bindings.js:158)
at bindings (bindings.js:60)
at Object. (rpio.js:17)
at Object../node_modules/rpio/lib/rpio.js (rpio.js:787)
at webpack_require (bootstrap 9ea40ba0fa93ccf9cb66:678)
at fn (bootstrap 9ea40ba0fa93ccf9cb66:88)
at Object../src/Services/switchController.js (switchController.js:1)
at webpack_require (bootstrap 9ea40ba0fa93ccf9cb66:678)
答案 3 :(得分:1)
斯威夫特 5
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
self.hidesBottomBarWhenPushed = true
}
答案 4 :(得分:0)
这是我的两分钱。 迅速3/4/5:
方法1 :(推荐)
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
if segue.identifier == "YourSegueIdentifier" {
let destinationController = segue.destinationViewController as! YourViewController
destinationController.hidesBottomBarWhenPushed = true // Does all the hide/show work.
}
}
方法2:
override func viewWillAppear(_ animated: Bool) { // As soon as vc appears
super.viewWillAppear(true)
self.tabBarController?.tabBar.isHidden = false
}
override func viewWillDisappear(_ animated: Bool) { // As soon as vc disappears
super.viewWillDisappear(true)
self.tabBarController?.tabBar.isHidden = true
}