How can I tell a UIGestureRecognizer to cancel an existing touch?

前端 未结 7 1044
佛祖请我去吃肉
佛祖请我去吃肉 2020-12-13 03:36

I have a UIPanGestureRecognizer I am using to track an object (UIImageView) below a user\'s finger. I only care about motion on the X axis, and if

7条回答
  •  囚心锁ツ
    2020-12-13 04:07

    You have a couple ways of handling this:

    1. If you were writing a custom pan gesture recognizer subclass, you could easily do this by calling -ignoreTouch:withEvent: from inside the recognizer when you notice it straying from the area you care about.

    2. Since you're using the standard Pan recognizer, and the touch starts off OK (so you don't want to prevent it with the delegate functions), you really can only make your distinction when you receive the recognizer's target actions. Check the Y value of the translationInView: or locationInView: return values, and clamp it appropriately.

提交回复
热议问题