Search code examples
iosswiftgestureuilongpressgesturerecogni

UILongPressGestureRecognizer to accept a flexible amount of touches


I have a UILongPressGestureRecognizer which is fired when there is 1 finger on the screen. However, as soon as I put 2 fingers, the function is not fired anymore and I need to create a new gesture for 2 fingers. How to have UILongPressGestureRecognizer to accept a flexible amount of touches ?

let longScreenGesture = UILongPressGestureRecognizer(target: self, action: #selector(screenTapped(_:)))
longScreenGesture.minimumPressDuration=0.1
longScreenGesture.allowableMovement=0
longScreenGesture.numberOfTouchesRequired=1
sceneView.isMultipleTouchEnabled=true
sceneView.addGestureRecognizer(longScreenGesture)

@objc func screenTapped(_ sender: UILongPressGestureRecognizer)
{
        print(sender.numberOfTouches) // -> Always displays 1
}

Solution

  • I ended up using TouchesBegan / Moved / Ended and analyzed gestures by myself