簡體   English   中英

當 swift 中所需的觸摸次數超過一個時,如何獲取 UILongPressGestureRecognizer 的觸摸位置?

[英]How do you get the location of touches for a UILongPressGestureRecognizer when the number of required touches is more than one in swift?

我想從 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 中的特定行為。 提前感謝您的任何幫助或建議!!!

您可以將location(ofTouch:in:)numberOfTouches結合使用:

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

這將為您提供CGPoint數組中的所有接觸點。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM