I want to detect 3 actions, "Tap begin", "Long press begin", "Long press ended". I want to detect "Tap begin" regardless of detection long tap (i.e. every time when touch the screen, detect "Tap begin") and detect "Tap begin" followed by "long press begin" in case keep touching.
Below code enables to detect "Tap begin" only in case "Long tap" is not detected.
let longPressGesture = UILongPressGestureRecognizer(target: self, action: #selector(self.Long(_:)))
longPressGesture.minimumPressDuration = 3
longPressGesture.allowableMovement = 30
let shortPressGesture = UITapGestureRecognizer(target: self, action: #selector(self.Tap(_:)))
touchView.addGestureRecognizer(shortPressGesture)
touchView.addGestureRecognizer(longPressGesture)
}
@objc func Long(_ sender: UILongPressGestureRecognizer) {
if(sender.state == UIGestureRecognizer.State.began) {
print("Long tap begin")
} else if (sender.state == UIGestureRecognizer.State.ended) {
print("Long tap ended")
}
}
@objc func Tap(_ sender: UITapGestureRecognizer) {
print("Tap begin")
}