The iOS UITapGestureRecognizer class has a built-in way to detect taps on any view. We can set the required taps based on our usage.
Pinch Gesture Recognizer - UIPinchGestureRecognizer
Other Gestures in iOS:
Swipe Gesture Recognizer - UISwipeGestureRecognizerPinch Gesture Recognizer - UIPinchGestureRecognizer
Pan Gesture Recognizer - UIPanGestureRecognizer
Long Press Gesture - UILongPressGestureRecognizer
UIRotationGestureRecognizer - Rotate Image View swift
Single Tap Gesture:
For detecting single tap gesture, here's an example:override func viewDidLoad() { super.viewDidLoad() let tapGesture = UITapGestureRecognizer(target: self, action: #selector(singleTap(gesture:))) view.addGestureRecognizer(tapGesture) } @objc func singleTap(gesture: UITapGestureRecognizer) { print("single tap called") }
Double Tap Gesture:
For detecting Double tap gesture is similar to above, just we need to set numberOfTapsRequired to 2.Here's an example:
override func viewDidLoad() { super.viewDidLoad() let tapGesture = UITapGestureRecognizer(target: self, action: #selector(doubleTap(gesture:))) tapGesture.numberOfTapsRequired = 2 view.addGestureRecognizer(tapGesture) } @objc func doubleTap(gesture: UITapGestureRecognizer) { print("double tap called") }
No comments:
Post a Comment