首页 > 解决方案 > 返回UINavigationController时如何隐藏UITabBar

问题描述

我有三个视图控制器:

我使用以下代码执行此操作,从 FeedController 到 PostController:

let postVC = PostController()
postVC.hidesBottomBarWhenPushed = true
pushViewController(postVC, animated: true)
postVC.hidesBottomBarWhenPushed = false

然后,从 PostVC 到 UserVC:

let userVC = UserController()
userVC.hidesBottomBarWhenPushed = false
pushViewController(userVC, animated: true)

它工作得很好。它显示UITabBar除了导航到帖子之外的任何地方。但是,当我从帖子中转到用户配置文件 (UserController) 时,就会出现问题。它UITabBar按预期显示在配置文件上,但是当我向后导航(使用我的后退按钮UINavigationController)时,UITabBar它仍然可见。当我从 userVC 返回 postVC 时,我希望它再次被隐藏。

有什么办法可以做到这一点吗?

标签: iosswiftuinavigationcontrolleruitabbarcontroller

解决方案


在您的帖子视图控制器中尝试:

  override func viewWillDisappear(_ animated: Bool) {
   postVC.hidesBottomBarWhenPushed = true
}

这将在视图即将消失时调用它,但在它出现时不会调用它,因此当您返回时它应该隐藏。


推荐阅读