How to remove panGesture after touch in swift
Asked Answered
U

1

1

I have a view that recognizes both a UIPanGesture and a single tap. How do I disable the pan gesture once the view has been tapped? I have tried multiple ways but cannot seem to figure it out. Here is the last method I tried:

 func gestureRecognizer(singleTapRecognizer: UIGestureRecognizer?, shouldRequireFailureOfGestureRecognizer panGesture: UIPanGestureRecognizer?) -> Bool? {
    print("in gesture recognizer")
    if wasTapped == true {
        return true
    }
    else {
        return false

    }

Thanks!

Unsatisfactory answered 28/8, 2015 at 15:39 Comment(1)
i mean you could disable it or set it to false gestureRecognizer.enabled = falseSer
C
2

I think you're looking for something along the lines of

panGesture.requireGestureRecognizerToFail(singleTapRecognizer)

Which would, preferably, be called just after you have created both of the gesture recognizers.

Consumedly answered 28/8, 2015 at 15:51 Comment(1)
Thanks!! I had tried that before but I had to declare variables as the gestures before manipulating them. It works now!Unsatisfactory

© 2022 - 2024 — McMap. All rights reserved.