UILongPressGestureRecognizer
suggest changeThe UILongPressGestureRecognizer
lets you listen for a long press on a view. You can set the length of delay before the action method is called.
Swift
override func viewDidLoad() {
super.viewDidLoad()
// Long Press
let longPressGesture = UILongPressGestureRecognizer(target: self, action: #selector(handleLongPress(_:)))
longPressView.addGestureRecognizer(longPressGesture)
}
// Long press action
func handleLongPress(gesture: UILongPressGestureRecognizer) {
if gesture.state == UIGestureRecognizerState.Began {
label.text = "Long press recognized"
}
}
Notes
- A fuller sample project can be found here.
- Change the
minimumPressDuration
to set the length of long press.
Found a mistake? Have a question or improvement idea?
Let me know.
Table Of Contents