返回 ViewController 时未设置 hidesBottomBarWhenPushed [英] hidesBottomBarWhenPushed not set when returning back to ViewController

查看:20
本文介绍了返回 ViewController 时未设置 hidesBottomBarWhenPushed的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我为我的 UIViewController 之一(称为 ViewControllerA)设置了 hidesBottomBarWhenPushed = true,它被推送到我的 UINavigationController 堆栈上.当我在 ViewControllerA 上推送一个新的 ViewController 时,我也选择显示底部栏.因此我有:

I have the hidesBottomBarWhenPushed = true set for one of my UIViewController's (call it ViewControllerA) that is pushed onto my UINavigationController stack. I also opt to show the bottomBar when I push a new ViewController ontop of ViewControllerA. Therefore I have:

class ViewControllerA: UIViewController {

override func viewWillDisappear(animated: Bool) {
    self.hidesBottomBarWhenPushed = false
}

override func viewWillAppear(animated: Bool) {
    self.hidesBottomBarWhenPushed = true
}

这一切正常.

当我按下 ViewControllerA 时,底部栏隐藏.当我推送任何其他 ViewController 时,底部栏会显示.

When I push ViewControllerA, the bottom bar hides. When I push any other ViewController, the bottom bar shows.

但是,当我在导航堆栈中向后移动(也就是点击 UIBarButtonItemBack 按钮)时,当我弹出导航堆栈以显示 ViewControllerA 时,我无法隐藏 bottomBar.

However, when I am traveling backwards in the navigation stack (aka hitting the UIBarButtonItemBack button), I cannot get the bottomBar to hide when I pop the navigation stack to reveal ViewControllerA.

我错过了什么?谢谢!

推荐答案

明白了!这是有效的:

class ViewControllerCustom: UIViewController {
  init() {
    self.hidesBottomBarWhenPushed = true
  }

  override func viewDidAppear(animated: Bool) {
    self.hidesBottomBarWhenPushed = false
  }
}

然后在每个 UIViewController 的 BarButtonItemBack 自定义实现中,我检查前一个视图控制器(将被弹出以隐藏标签栏).当然,我把它抽象成一个通用函数,所以我不需要重复代码,但这是概念.感谢您帮助解决这个问题!

And then in every UIViewController's custom implementation of BarButtonItemBack pressed I check to see if the previous view controller (that will be popped to needs to hide the tab bar). Granted I abstracted this out into a general function so I didn't need to repeat code, but here's the concept. Thanks for the help figuring this out though!

func barButtonItemBackPressed(button: UIButton) {

  var viewControllers = self.navigationController!.viewControllers as! [UIViewController]
  if ((viewControllers[viewControllers.count - 2]).isKindOfClass(ViewControllerCustom.self)) {
    (viewControllers[viewControllers.count - 2] as! ViewControllerCustom).hidesBottomBarWhenPushed = true
  }

  self.navigationController?.popViewControllerAnimated(true)
}

这篇关于返回 ViewController 时未设置 hidesBottomBarWhenPushed的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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