UILongPressGestureRecognizer

suggest change

The 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

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:



Table Of Contents