-(void)singleTap{
NSLog(@"Tap 1 time");
}
-(void)doubleTap{
NSLog(@"Tap 2 time");
}
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
UITouch *touch = [touches anyObject];
NSTimeInterval delaytime = 0.4;//自己根据需要调整
switch (touch.tapCount) {
case 1:
[self performSelector:@selector(singleTap) withObject:nil afterDelay:delaytime];
break;
case 2:{
[NSObject cancelPreviousPerformRequestsWithTarget:self selector:@selector(singleTap) object:nil];
[self performSelector:@selector(doubleTap) withObject:nil afterDelay:delaytime];
}
break;
default:
break;
}
}
区分 touch 事件是单击还是双击
最新推荐文章于 2021-08-27 16:35:25 发布
用户双击 view 时,总是先执行一遍单击的操作再执行双击的操作。所以直接判断时就会发现不能直接进入双击操作。下面是区分 touch 事件是单击还是双击的方法