ios - TapGesture 在 tabBar 下不起作用

标签 ios swift uitabbar

我有一个“经典应用程序”,带有 3 个 ViewController 和一个用于更改 ViewController 的 tabBar。

在我的第一个 ViewController 上,我有一个在整个屏幕上显示 UIView 的按钮,因此我使用 setTabBarVisible 函数隐藏 tabBar :

extension UIViewController
{

func setTabBarVisible(visible: Bool, animated: Bool)
{
    //* This cannot be called before viewDidLayoutSubviews(), because the frame is not set before this time

    // bail if the current state matches the desired state
    if (isTabBarVisible == visible) { return }

    // get a frame calculation ready
    let frame = self.tabBarController?.tabBar.frame
    let height = frame?.size.height
    let offsetY = (visible ? -height! : height)

    // zero duration means no animation
    let duration: TimeInterval = (animated ? 0.3 : 0.0)

    //  animate the tabBar
    if frame != nil
    {
        UIView.animate(withDuration: duration)
        {
            self.tabBarController?.tabBar.frame = frame!.offsetBy(dx: 0, dy: offsetY!)
            return
        }
    }
}

var isTabBarVisible: Bool
{
    return (self.tabBarController?.tabBar.frame.origin.y ?? 0) < self.view.frame.maxY
}
}

工作正常,tabBar 已隐藏,我可以看到所有 UIVIew。 问题是,我在 UIView 底部有一个 UILabel (在我通常显示 tabBar 的地方),并且我无法在 UILabel 上使用 TapGesture,什么也没有发生。 (如果我在其他地方显示标签,UITapGesture 效果很好。)

我尝试将 tabBar 的 zPosition 设置为 0,将 UIView 的 zPosition 设置为 1,但这也不起作用。

如何让我的标签在 View 底部可点击?

最佳答案

检查 UILabel.isUserInterration = 启用

确保隐藏选项卡栏时,特定 View Controller 在底部栏属性下未选择。 See atteh imnage.

您也可以尝试以编程方式进行操作,例如

ViewController.edgesForExtendedLayout = UIRectEdge.top

关于ios - TapGesture 在 tabBar 下不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50507542/

相关文章:

iphone - 向 TTTable View Item 添加一个按钮

arrays - Swift:HackerRank readLine 一个 Int 数组

ios - 弹出 UIViewController 时奇怪的 Tabbar 动画

ios - UITabBar 图片不清晰

iphone - UITabBar Controller 的滑动动画,在 objective-c 中水平?

ios - 根据所需语言检索文件

ios - 如何从 foursquare 获取用户的特定 friend 的签到?

ios - 将 NSArray 的内容加载到 UITableView 中

ios - UIImagePicker : How to always pick square image from camera library?

ios - 如何在 X 分钟后发出通知?