推/回时隐藏/显示标签栏.迅速 [英] hide / show tab bar when push / back. swift

查看:68
本文介绍了推/回时隐藏/显示标签栏.迅速的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

答案: 在每个视图控制器中使用self.tabBarController?.tabBar.hidden而不是hidesBottomBarWhenPushed来管理视图控制器是否应显示选项卡栏.

Answer: Use self.tabBarController?.tabBar.hidden instead of hidesBottomBarWhenPushed in each view controller to manage whether the view controller should show a tab bar or not.

override func viewWillAppear(animated: Bool) {
    self.tabBarController?.tabBar.hidden = true/false
} 


我想要


I want

视图控制器1:应该显示标签栏

view controller 1: tab bar should be showed

视图控制器2:应该显示标签栏

view controller 2: tab bar should be showed

视图控制器3:不应显示标签栏.

view controller 3: tab bar should not be showed.

视图控制器4:不应显示标签栏.

view controller 4: tab bar should not be showed.

我写了

// 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,则起作用.

if 1 -> 3 then back to 1, works.

如果1-> 3-> 2然后回到3再回到1,就可以工作.

if 1 -> 3 -> 2 then back to 3 and back to 1, works.

如果2-> 4,然后回到2,就可以工作.

if 2 -> 4, then back to 2, works.

如果1-> 3-> 2-> 4,然后返回2,则不显示选项卡栏.想知道为什么.对hidesBottomBarWhenPushed的任何建议或解释,都会使我感到困惑

if 1 -> 3 -> 2 -> 4 then back to 2, tab bar is not showed. Wondering why. Any suggestions or some explanation of hidesBottomBarWhenPushed as it confuses me a lot

推荐答案

顾名思义,hiddenBottomBarWhenPushed仅在需要时隐藏底部栏,而不会取消隐藏bottomBar. 您可以这样做以使其正常工作:

As it's name suggest, hiddenBottomBarWhenPushed only hide bottom bar if needed, it will not unhide bottomBar. You can do this to get it works:

override func viewWillAppear(animated: Bool) {
    super.viewWillAppear(animated)
    self.tabBarController?.tabBar.hidden = true/false
} 

或直接将self.tabBarController?.tabBar.hidden = true/false放入prepareForSegue

or simply put self.tabBarController?.tabBar.hidden = true/false in prepareForSegue

但是我不建议您这样做,因为如果bottomBar突然弹出会很奇怪,用户会认为它们突然回到了rootViewController而不是.

用户应始终知道他们在您的应用中的位置以及如何到达下一个目的地.

Users should always know where they are in your app and how to get to their next destination.

这篇关于推/回时隐藏/显示标签栏.迅速的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆