Search code examples
iosswift3uiswipegesturerecognizer

How to disable Swipe Gesture recognizer when a button is pressed?


I set up the recognizer like this:

    @IBAction func changeSeq(_ recognizer: UISwipeGestureRecognizer) {

    if (recognizer.direction == UISwipeGestureRecognizerDirection.left)
    {
    print ("nice")
    }
}

I need it disabled when the start button is pressed and enabled again when the pause is triggered. I don't want to disable all user interaction. How do I handle the swipe specifically?


Solution

  • In your start button IBAction code, set the gesture recognizer's enabled property to false, and in the pause button's IBAction, set enabled = true.

    That's cleaner than setting the delegate to nil.