我正在捕捉触摸事件。我需要区分两个事件 1)用户触摸屏幕,然后举起一个手指 2)用户触摸屏幕,不要举起手指 如何区分两个事件?我需要区分两个触摸事件。我怎样才能区分两个事件?
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
if (isFirstCase)
{}
if (isSecondCase)
{}
}
我正在捕捉触摸事件。我需要区分两个事件 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
- 与此特定触摸相关的此对象的数组。
祝你有美好的一天:)
您可以使用手势识别:
首先,你需要注册的手势识别:
UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]
initWithTarget:self
action:@selector(handleTap:)];
[myView addGestureRecognizer:tap];
UILongPressGestureRecognizer *longPress = [[UILongPressGestureRecognizer alloc]
initWithTarget:self
action:@selector(handleLongPress:)];
longPress.minimumPressDuration = 1.0;
[myView addGestureRecognizer:longPress];
然后,你必须写操作方法:
- (void)handleTap:(UITapGestureRecognizer *)gesture
{
// simple tap
}
- (void)handleLongPress:(UILongPressGestureRecognizer *)gesture
{
// long tap
}