popToRootViewController 后没有显示 Tabbar [英] Tabbar is not showing up after popToRootViewController

查看:26
本文介绍了popToRootViewController 后没有显示 Tabbar的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的应用程序中,我通过设置 UIViewControllerhidesBottomBarWhenPushed 属性来隐藏标签栏.我不确定这种行为是否被设计,当我调用 popToRootViewController 来弹出所有视图控制器堆栈时,如果我之后推送相同的视图控制器,标签栏没有正确显示.即使我在调用 popToRootViewController 后尝试通过设置 isHidden 属性来显示标签栏,但它也不起作用.奇怪的部分是,在标签栏消失后,我推了同一个视图控制器,当我尝试使用手势弹出(滑动弹出)弹出视图控制器(不是 popToRootViewController)时,我可以看到标签栏.虽然它在转换完成时消失了.

In my application, I hide tabbar by setting hidesBottomBarWhenPushed property of UIViewController. I'm not sure this behavior is designed or not, when I called popToRootViewController to pop all view controller stack, tabbar did not show properly if I pushed same view controller after. Even I tried to show tabbar by setting isHidden property after I called popToRootViewController but it didn't work neither. Weird part is, after tabbar disappeared, I pushed same view controller and I could see the tabbar when I tried to pop the view controller (not popToRootViewController) by using gesture to pop (swipe to pop). Though it disappeared when transition was completed.

仅供参考,这是逐步产生这种行为的方法.

FYI, this is step by step to produce this behavior.

  1. 在两个选项卡上初始化选项卡栏和导航控制器.
  2. 在一个标签的导航控制器上推送视图控制器(hidesBottomBarWhenPushed 为真)
  3. 通过调用 popToRootViewController 从导航控制器弹出所有视图控制器4 通过在 tabbarController
  4. 上设置 selectedIndex 来更改标签索引
  5. 推送同一个视图控制器
  1. init tabbar and navigation controllers on two tabs.
  2. push view controller (hidesBottomBarWhenPushed is true) on one tab's navigation controller
  3. pop all view controller from the navigation controller by calling popToRootViewController 4 change tab index by setting selectedIndex on tabbarController
  4. push the same view controller

hidesBottomBarWhenPushed 属性如何详细显示/隐藏标签栏?

How does hidesBottomBarWhenPushed property work in detail to show/hide tabbar?

推荐答案

我会在我的应用中讨论这个问题.

I'll talk about the problem in my app.

对于每个页面,我都会编辑self.navigationController?.navigationBar.isHiddenself.tabBarController?.tabBar.isHidden = false 以保证状态viewWillAppear 中的 tabBarnavigationBar.

For every pages, I'll edit the self.navigationController?.navigationBar.isHidden and self.tabBarController?.tabBar.isHidden = false to guarantee the state of tabBar and navigationBar in the viewWillAppear.

// In this viewController, I'll show the navigation bar and hide tab bar
override func viewWillAppear(_ animated: Bool) {
    super.viewWillAppear(animated)
    self.navigationController?.navigationBar.isHidden = false
    self.tabBarController?.tabBar.isHidden = true
}

navigationBartabBar 可以在您推送新视图控制器或弹出旧视图控制器时保持其状态与上一个视图控制器相同.所以它会让我们在每个视图控制器中设置来控制和确保它的状态.

The navigationBar and tabBar can keep their state from last view controller when you push a new one or pop a old one. So it will let we set in every view controller to control and ensure its state as I wish.

这篇关于popToRootViewController 后没有显示 Tabbar的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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