tap gesture recognizer swift code example
Example 1: swift uiview add tap gesture
let tap = UITapGestureRecognizer(target: self, action: #selector(self.handleTap(_:)))
myView.addGestureRecognizer(tap)
// Then, you should implement the handler, which will be called each time when a tap event occurs:
@objc func handleTap(_ sender: UITapGestureRecognizer? = nil) {
// handling code
}
Example 2: using swipe gesture recognizer swift
@IBAction func swipeHandler(_ gestureRecognizer : UISwipeGestureRecognizer) {
if gestureRecognizer.state == .ended {
// Perform action.
}
}