答案:在每个视图控制器中使用self.tabBarController?.tabBar.hidden而不是hidesBottomBarWhenPushed来管理视图控制器是否应该显示选项卡条。
override func viewWillAppear(animated: Bool) {
self.tabBarController?.tabBar.hidden = true/false
} 我想要
视图控制器1:应该显示选项卡条
视图控制器2:应该显示选项卡条
视图控制器3:不应该显示选项卡条。
视图控制器4:不应该显示选项卡条。
我写
// 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,工作。
如果1 -> 3 -> 2,然后返回3和返回1,工作。
如果2 -> 4,然后回到2,工作。
如果1 -> 3 -> 2 -> 4返回到2,则不会显示选项卡条。想知道为什么。任何关于hidesBottomBarWhenPushed的建议或解释都会让我很困惑

发布于 2022-05-02 05:50:58
淡出总比躲藏好..。
(....我的天,嘿)
Swift 5:
另一种方法..。就是淡出标签栏..。并不是说这在战略上比其他任何一个都更有利,比如那些需要prepareForSegue的,但是它可以适应其他的触发器。在任何情况下,动画选项卡α通过淡入和淡出避免了在tabBar (UIView)上设置UIView时的严酷的消失/出现效果。在VC被推送或加载时需要隐藏的任何VC中都会这样做,在VC被弹出或卸载时解除隐藏。
这将不会麻烦地恢复选项卡栏,直到在navBar或等效操作中按下后退按钮,这样当子VC被推到上面时,选项卡条将保持隐藏状态,这通常(但并不总是)有意义。
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
UIView.animate(withDuration: 0.4, delay: 0.0, options: UIView.AnimationOptions.curveEaseOut, animations: {
self.tabBarController?.tabBar.alpha = 0.0
}, completion: { (finished: Bool) -> Void in
self.tabBarController?.tabBar.isUserInteractionEnabled = false
})
}
override func viewWillDisappear(_ animated: Bool) {
if self.isMovingFromParent {
UIView.animate(withDuration: 0.4, delay: 0.0, options: UIView.AnimationOptions.curveEaseOut, animations: {
self.tabBarController?.tabBar.alpha = 1.0
}, completion: { (finished: Bool) -> Void in
self.tabBarController?.tabBar.isUserInteractionEnabled = true
})
}
}https://stackoverflow.com/questions/35427102
复制相似问题