【问题标题】:TapGesture doesn't work under tabBarTapGesture 在 tabBar 下不起作用
【发布时间】:2018-05-24 10:54:43
【问题描述】:

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

在我的第一个 ViewController 上,我有一个在整个屏幕上显示 UIView 的按钮,所以我用这个 setTabBarVisible func 隐藏了 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,但这也不起作用。

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

【问题讨论】:

  • 确保您的标签在您的视图范围内。尝试将视图的 clipsToBounds 属性设置为 true。如果标签被剪裁,则意味着它超出了视图范围,因此不会将触摸传递给它。
  • 我在 UIView 的 viewDidLoad() 中尝试使用“self.clipsToBounds = true”,但我仍然可以看到我的 UILabel,所以我想这不是问题所在。还是谢谢
  • 我找到了解决方案。这与我的视图范围有关,我正在将该视图添加到另一个视图中,而另一个视图的高度不足以容纳我所有的新视图。

标签: ios swift uitabbar


【解决方案1】:

检查 UILabel.isUserInterration = 启用

确保当你隐藏标签栏时,底部栏属性下的特定视图控制器是 unselect 。 See atteh imnage.

您也可以通过编程方式尝试

ViewController.edgesForExtendedLayout = UIRectEdge.top

【讨论】:

    【解决方案2】:

    确定是真的

    label.isUserInteractionEnabled = true

    Please refer this link may it help you.

    【讨论】:

    • 是的,这已经是真的了,正如我所说,如果我的标签不在底部(通常是 tabBar 的位置),我可以点击我的标签,一切正常。不过谢谢
    猜你喜欢
    • 1970-01-01
    • 2019-07-12
    • 2015-07-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-04-02
    • 2020-10-25
    • 1970-01-01
    相关资源
    最近更新 更多