Swift / iOS:触摸标签栏项时隐藏TabBar [关闭]

问题描述 投票:-1回答:1

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

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

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

或者,我想在触摸此特定标签栏项目时离开栏控件,并在触摸取消按钮时返回该栏控件。

非常感谢你!

ios swift xcode uitabbarcontroller tabbar
1个回答
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(使用可选动画)。

© www.soinside.com 2019 - 2024. All rights reserved.