UITapGestureRecognizer Double Tap
suggest changeThe 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
to3
.
Found a mistake? Have a question or improvement idea?
Let me know.
Table Of Contents