ios - 我需要区分两个触摸事件。如何区分两个事件?

标签 ios uievent

我正在抓触摸事件。我需要区分两个事件
1)用户触摸屏幕然后松开手指
2)用户触摸屏幕但不松开手指
如何区分两个事件?

-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
 if (isFirstCase)
 {}
 if (isSecondCase)
 {}
}

最佳答案

(NSSet *)touches属性包含UITouch对象,每个对象都包含几个有用的属性:

@property(nonatomic, readonly) NSUInteger tapCount
@property(nonatomic, readonly) NSTimeInterval timestamp
@property(nonatomic, readonly) UITouchPhase phase
@property(nonatomic,readonly,copy) NSArray *gestureRecognizers

typedef enum {
    UITouchPhaseBegan,
    UITouchPhaseMoved,
    UITouchPhaseStationary,
    UITouchPhaseEnded,
    UITouchPhaseCancelled,
} UITouchPhase;

相位和tapCount是用于识别触摸类型的非常有用的属性。
检查是否可以使用UIGestureRecognizers。 NSArray *gestureRecognizers-与此特定触摸相关的此对象的数组。

祝你今天愉快 :)

关于ios - 我需要区分两个触摸事件。如何区分两个事件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9885681/

相关文章:

iphone - 无法从 C++ 文件访问对象属性 (Cocos2D/Box2d)

objective-c - -[国家保留] : message sent to deallocated instance 0x6829280

ios - 核心蓝牙: Find out if device is available for reconnection

ios - 应用程序在 sendEvent 方法上崩溃

objective-c - 自定义 UIControl 始终发送 nil UIEvent 对象

ios - 如何解析不同的字符串日期

ios - 使用 xcodebuild 指定单独的目标build设置

ios - 获取 UIView 上的最后一个触摸事件

objective-c - 在 C++ 类中接收 UI 事件

ios - 当 View 已经被按下时如何响应触摸?