UITouch碰到的小问题

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

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

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

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

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

- (void)touchesCancelled:(nullable NSSet *)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.

你可能感兴趣的:(UITouch碰到的小问题)