1

I am trying to recognise if users tap a single tap once or double-tap

if (gestureRecognizer.numberOfTouchesRequired == 2 ){
            print("Double")

        }else{print("single")
} 

Thank you for you advice

ASN
  • 21
  • 3
  • 3
    Does this answer your question? [UITapGestureRecognizer - single tap and double tap](https://stackoverflow.com/questions/8876202/uitapgesturerecognizer-single-tap-and-double-tap) – El Tomato Sep 28 '21 at 23:09
  • 1
    You aren't the first to ask this question. Not even the second... – El Tomato Sep 28 '21 at 23:10

1 Answers1

1

you will need to use two gesture recognizers for this . One to capture the single tap gestures and another for double taps .

Sample code :

let singleTapGesture = UITapGestureRecognizer(target: self, action: #selector(didPressPartButton))
singleTapGesture.numberOfTapsRequired = 1
view.addGestureRecognizer(singleTapGesture)

let doubleTapGesture = UITapGestureRecognizer(target: self, action: #selector(didDoubleTap))
doubleTapGesture.numberOfTapsRequired = 2
view.addGestureRecognizer(doubleTapGesture)