【问题标题】:How do you get the location of touches for a UILongPressGestureRecognizer when the number of required touches is more than one in swift?当所需的触摸次数超过一次时,如何获得 UILongPressGestureRecognizer 的触摸位置?
【发布时间】:2020-11-21 21:06:42
【问题描述】:

我想从 UILongPressGuestureRecognizer 中获取多个多次触摸的位置,其中所需的触摸次数不止一个。我知道我可以执行以下操作来获取使用一根手指时的位置。

let twoFingerLongPressGesture = UILongPressGestureRecognizer(target: self, action: #selector(twoFingerLongPressChordTouchView(gesture:)))
twoFingerLongPressGesture.numberOfTouchesRequired = 2
twoFingerLongPressGesture.minimumPressDuration = 0.02
self.addGestureRecognizer(twoFingerLongPressGesture)
@objc func twoFingerLongPressAction(gesture: UILongPressGestureRecognizer) {
    let location = gesture.location(in: self)
}

我也知道我可以在触摸开始回调中迭代触摸,但是我正在尝试利用 UILongPressGestureRecognizer 中的特定行为。提前感谢您的任何帮助或建议!!!

【问题讨论】:

    标签: swift location touches uilongpressgesturerecogni


    【解决方案1】:

    您可以将location(ofTouch:in:)numberOfTouches 结合使用:

    let touchPoints = (0..<twoFingerLongPressGesture.numberOfTouches).map {
        twoFingerLongPressGesture.location(ofTouch: $0, in: self)
    }
    

    这将为您提供CGPoints 数组中的所有接触点。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-03-29
      • 1970-01-01
      相关资源
      最近更新 更多