简体   繁体   中英

How to remove panGesture after touch in swift

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!

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM