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

前端 未结 7 1085
佛祖请我去吃肉
佛祖请我去吃肉 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 03:49

    This little trick works for me.

    @implementation UIGestureRecognizer (Cancel)
    
    - (void)cancel {
        self.enabled = NO;
        self.enabled = YES;
    }
    
    @end
    

    From the UIGestureRecognizer @enabled documentation:

    Disables a gesture recognizers so it does not receive touches. The default value is YES. If you change this property to NO while a gesture recognizer is currently recognizing a gesture, the gesture recognizer transitions to a cancelled state.

提交回复
热议问题