How to remove panGesture after touch in swift

2019-08-12 06:02发布

问题:

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!

回答1:

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.