我有三个视图控制器:
- 馈电控制器(
UITabBar
可见) - 后控制器(
UITabBar
隐藏) - 用户控制器 (
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
,但导航到帖子时除外。但是,当我从帖子中转到用户配置文件(用户控制器)时,会出现此问题。它按预期显示配置文件上的UITabBar
,但是当我向后导航(使用UINavigationController
中的后退按钮)时,UITabBar
仍然可见。我希望当我从用户VC返回到postVC时再次隐藏它。
有什么方法可以做到这一点吗?
在你的帖子视图中尝试控制器:
override func viewWillDisappear(_ animated: Bool) {
postVC.hidesBottomBarWhenPushed = true
}
这将在视图即将消失时调用它,但在它出现时不会调用它,因此当您返回时它应该隐藏。