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

问题:

使用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;

解决办法:

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];

可以参考一下!

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • **2014真题Directions:Read the following text. Choose the be...
    又是夜半惊坐起阅读 10,061评论 0 23
  • 手势识别状态机 Interacting with Other Gesture Recognizers When a...
    杰米阅读 879评论 0 0
  • ViewsBecause view objects are the main way your applicati...
    梁光飞阅读 656评论 0 0
  • 01 周末午后恰好有个小段的空余时间,早就想改变我那半长不短头发和天天一个式样的马尾,遂有了剪短的想法,索性趁着空...
    紫橄榄阅读 257评论 0 1
  • 半夜醒来,想起多年前的一个愿望,并发现它已经超出预期很多的实现了的时候,才明白,人都是贪得无厌的。 很久以前,他在...
    梨花开阅读 202评论 0 2