iOS手势:正常滑动时,一直调用- (void)touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event;

问题:

使用iOS手势,按照正常来说,应该是首先调用了touchesbegain,结束时调用touchesend,只有发生系统事件时,才会调用touchesCancel,但是遇到一个问题就是,一直最开始就调用touchescancel,执行不到touchesend,所以调用不了方法.

- (void)touchesBegan:(NSSet *)touches withEvent:(nullable UIEvent *)event;
- (void)touchesMoved:(NSSet *)touches withEvent:(nullable UIEvent *)event;
- (void)touchesEnded:(NSSet *)touches withEvent:(nullable UIEvent *)event;
- (void)touchesCancelled:(NSSet *)touches withEvent:(nullable UIEvent *)event;

解决办法:

UIGestureRecognizer

有一个cancelsTouchesInView属性

cancelsTouchesInView
—If a gesture recognizer recognizes its gesture, it unbinds the remaining touches of that gesture from their view (so the window won’t deliver them). The window cancels the previously delivered touches with a (touchesCancelled(_:with:)
) message. If a gesture recognizer doesn’t recognize its gesture, the view receives all touches in the multi-touch sequence.

查找资料过程中还发现一个问题

Note: touches also get cancelled if you start a UIView
animation after touchesBegan

. To prevent this make sure you include UIViewAnimationOptionAllowUserInteraction:

[UIView animateWithDuration:0.3 delay:0 options:UIViewAnimationOptionAllowUserInteraction animations:^{ self.aView.hidden = NO; self.aView.alpha = 1; } completion:nil];

可以参考一下!

你可能感兴趣的:(iOS手势:正常滑动时,一直调用- (void)touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event;)