问题:
使用iOS手势,按照正常来说,应该是首先调用了touchesbegain,结束时调用touchesend,只有发生系统事件时,才会调用touchesCancel,但是遇到一个问题就是,一直最开始就调用touchescancel,执行不到touchesend,所以调用不了方法.
- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(nullable UIEvent *)event;
- (void)touchesMoved:(NSSet<UITouch *> *)touches withEvent:(nullable UIEvent *)event;
- (void)touchesEnded:(NSSet<UITouch *> *)touches withEvent:(nullable UIEvent *)event;
- (void)touchesCancelled:(NSSet<UITouch *> *)touches withEvent:(nullable UIEvent *)event;
解决办法:
有一个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];
可以参考一下!