iOS UITapGestureRecognizer (Double Tap)


Example

The double tap, like a single tap, also uses the UITapGestureRecognizer. You simply set the numberOfTapsRequired to 2.

Swift

override func viewDidLoad() {
    super.viewDidLoad()

    // Double Tap
    let doubleTapGesture = UITapGestureRecognizer(target: self, action: #selector(handleDoubleTap))
    doubleTapGesture.numberOfTapsRequired = 2
    doubleTapView.addGestureRecognizer(doubleTapGesture)
}

// Double tap action
func handleDoubleTap() {
    label.text = "Double tap recognized"
}

Notes

  • A sample project can be found here.
  • You could recognize a triple tap by setting the numberOfTapsRequired to 3.