UITouch碰到的小问题

函数返回一个CGPoint类型的值,表示触摸在view这个视图上的位置,这里返回的位置是针对view的坐标系的。调用时传入的view参数为空的话,返回的时触摸点在整个窗口的位置。

- (CGPoint)locationInView:(nullable UIView *)view;

该方法记录了前一个坐标值,函数返回也是一个CGPoint类型的值, 表示触摸在view这个视图上的位置,这里返回的位置是针对view的坐标系的。调用时传入的view参数为空的话,返回的时触摸点在整个窗口的位置。

- (CGPoint)previousLocationInView:(UIView *)view:

写自定义贴纸的时候碰到了一个坑的问题,贴纸本身本质上下左右移动和旋转缩放,在DEMO里没有任何问题,在项目里时上下移动就会触发

- (void)touchesCancelled:(nullable NSSet<UITouch *> *)touches withEvent:(nullable UIEvent *)event;

导致触摸失效
而左右斜着移动没有任何问题Σ(゚д゚;)

Sent to the responder when a system event (such as a low-memory warning) cancels a touch event.
This method is invoked when the Cocoa Touch framework receives a system interruption requiring cancellation of the touch event; for this, it generates a UITouch object with a phase of UITouchPhaseCancel. The interruption is something that might cause the application to be no longer active or the view to be removed from the window
When an object receives a touchesCancelled:withEvent: message it should clean up any state information that was established in its touchesBegan:withEvent: implementation.
The default implementation of this method does nothing. However immediate UIKit subclasses of UIResponder, particularly UIView, forward the message up the responder chain. To forward the message to the next responder, send the message to super (the superclass implementation); do not send the message directly to the next responder. For example,
[super touchesCancelled:touches withEvent:event];
If you override this method without calling super (a common use pattern), you must also override the other methods for handling touch events, if only as stub (empty) implementations.

最后发现的原因是控制器的父控制器加了UISwipeGestureRecognizer
而这个手势导致了上面的方法被触发从而使触摸失效
解决:

GestureRecognizer.cancelsTouchesInView = NO;

// default is YES. causes touchesCancelled:withEvent: or pressesCancelled:withEvent: to be sent to the view for all touches or presses recognized as part of this gesture immediately before the action method is called.

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

推荐阅读更多精彩内容

  • 一. Hit-Testing 什么是Hit-Testing?对于触摸事件, window首先会尝试将事件交给事件触...
    面糊阅读 892评论 0 50
  • 好奇触摸事件是如何从屏幕转移到APP内的?困惑于Cell怎么突然不能点击了?纠结于如何实现这个奇葩响应需求?亦或是...
    Lotheve阅读 58,251评论 51 603
  • ViewsBecause view objects are the main way your applicati...
    梁光飞阅读 642评论 0 0
  • 在iOS开发中经常会涉及到触摸事件。本想自己总结一下,但是遇到了这篇文章,感觉总结的已经很到位,特此转载。作者:L...
    WQ_UESTC阅读 6,140评论 4 26
  • 俊俊+女+201203 20170519-20170618亲子打卡月度检视 #尊重,平等,爱# 孩子第2个30天目...
    婷婷_409c阅读 142评论 0 1