美文网首页
UITouch碰到的小问题

UITouch碰到的小问题

作者: i_Leechee | 来源:发表于2015-12-16 09:46 被阅读294次

函数返回一个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.

相关文章

  • UITouch碰到的小问题

    函数返回一个CGPoint类型的值,表示触摸在view这个视图上的位置,这里返回的位置是针对view的坐标系的。调...

  • iOS触摸事件详解

    目录:1 UITouch1.1 UITouch的创建1.2 UITouch的作用1.3 UITouch的常用属性1...

  • UITableView 碰到的小问题

    小编开发过程中发现了一个诡异的问题,使用 tableView 设置了 section 的 footView,因为页...

  • iOS_UITouch 事件

    UITouch 基本事件函数 UITouch 包含如下四个基本函数,touches 集合中存储的事UITouch ...

  • UITouch

    1:触摸事件 2:加速计事件 3:远程控制事件 UITouch UITouch的属性 UITouch的方法 UIE...

  • IOS开发 UITouch

    本节学习内容: 1.UITouch的基本概念 2.UITouch的作用周期 3.UITouch的应用 【viewC...

  • jni编程碰到的小问题

    JNI error: java.lang.UnsatisfiedLinkError: No implementat...

  • jni编程碰到的小问题

    这个问题困扰了两天,出现这个问题的时候已经不是找不到库的问题了, dlopen肯定是过了。 这个是因为找不到需要调...

  • iOS UITouch

    UITouch UITouch的属性 触摸产生时所处的窗口 @property(nonatomic,readonl...

  • 触摸事件

    响应者对象 UIResponder UIView的触摸事件处理 UITouch UITouch的属性 UITouc...

网友评论

      本文标题:UITouch碰到的小问题

      本文链接:https://www.haomeiwen.com/subject/ronuhttx.html