Если вы добавляете жест на imageView
, вам нужно включить isUserInteractionEnabled
.
imageView.isUserInteractionEnabled = true
И если вы добавляете жест на UIButton
, тогда
@IBOutlet weak var button: UIButton!
override func viewDidLoad() {
let tapGesture = UITapGestureRecognizer(target: self, #selector (tapGestureActionHandler(_:))) //Tap function will call when user tap on button
let longGesture = UILongPressGestureRecognizer(target: self, #selector(longGestureActionHandler(_:))) //Long function will call when user long press on button.
tapGesture.numberOfTapsRequired = 1
button.addGestureRecognizer(tapGesture)
button.addGestureRecognizer(longGesture)
}
@objc func tapGestureActionHandler(_ gesture: UITapGestureRecognizer) {
print("Tap happend")
}
@objc func longGestureActionHandler(_ gesture: UILongPressGestureRecognizer) {
print("Long press")
}