Swift / iOS:触摸标签栏项目时隐藏标签栏

时间:2018-09-10 17:02:48

标签: ios swift xcode uitabbarcontroller tabbar

我是iOS编程的新手,非常感谢您的帮助!

我有一个包含多个项目的标签栏。 当特定的标签栏项目被触摸时,我希望标签栏被隐藏,直到用户通过触摸取消按钮离开触发视图。

类似于:self.hidesBottomBarWhenPushed = true,但不仅限于将视图控制器推入导航堆栈时。

或者,我想在触摸此特定选项卡栏项目时保留条形控件,而在触摸取消按钮时返回到它。

非常感谢您!

1 个答案:

答案 0 :(得分:0)

您可以在触发的视图控制器的viewWillAppear方法中隐藏标签栏:

override func viewWillAppear(_ animated: Bool) {
    super.viewWillAppear(animated)

    // without animation
    tabBarController?.tabBar.isHidden = true

    // with animation
    UIView.animate(withDuration: 0.25, animations: {
        self.tabBarController?.tabBar.alpha = 0
    }) { _ in
        self.tabBarController?.tabBar.isHidden = true
    }
}

要再次显示标签栏时,只需将其isHidden属性设置为false(带有可选动画)。

相关问题