【问题标题】:AKButton and gesture tap conflictAKButton和手势点击冲突
【发布时间】:2020-02-04 11:39:59
【问题描述】:

我有一个弹出 UIView 作为控制窗口。包含来自 AudioKitUI 框架的滑块和按钮。 我设置了一个触摸点击手势来关闭弹出视图,但当然当我点击一个按钮时它也会关闭 UIview。 AKButton按下时是否可以忽略点击手势?

一切都包含在自己的类结构中。 这是我的 Overide Init 顶部的手势代码。

override init(frame: CGRect) {
        super.init(frame: frame)

        self.addGestureRecognizer(UITapGestureRecognizer(target: self, action: #selector(animateout)))

还有我的 AKButton 的代码。

   // Dynamics on/off button
        let dynamicsButton = AKButton(title: "") { button in
            if boxDynamicStatus[boxBloqDoubleTapped] == false {
                button.title = "FLOATING"
                boxDynamicStatus[boxBloqDoubleTapped] = true
                boxBloqArray[boxBloqDoubleTapped].physicsBody?.isDynamic = true
            } else {
                boxDynamicStatus[boxBloqDoubleTapped] = false
                button.title = "FIXED"
                boxBloqArray[boxBloqDoubleTapped].physicsBody?.isDynamic = false
            }
        }
        // Set button text from box array
        if boxDynamicStatus[boxBloqDoubleTapped] == false {
            dynamicsButton.title = "FIXED"
        } else {
            dynamicsButton.title = "FLOATING"
        }

我认为滑块没有这个问题是因为移动手势而不是点击。

所有按钮/滑块都保存在一个容器中

fileprivate let container: UIView = {
        let v = UIView()
        v.translatesAutoresizingMaskIntoConstraints = false
        v.backgroundColor = UIColor.black.withAlphaComponent(0.3)
        v.layer.cornerRadius = 5

        return v

    }()

可以将手势编程为不在容器边缘内注册吗?

【问题讨论】:

    标签: ios swift uigesturerecognizer audiokit


    【解决方案1】:

    我认为这可能与这里的问题实际上是相同的:Prevent click through view in swift

    因此,可以通过视图的 z-index 排序来解决。如果您提供了代码的工作版本或某个游乐场版本,我可以进行测试,但这是我可以根据给出的信息提出的最佳建议。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-04-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-09-22
      • 1970-01-01
      • 2016-05-30
      相关资源
      最近更新 更多