如果您的 iPhone 應(yīng)用里有個(gè) view,既有單擊操作又有雙擊操作榛瓮。用戶(hù)雙擊 view 時(shí)铺董,總是先執(zhí)行一遍單擊的操作再執(zhí)行雙擊的操作。所以直接判斷時(shí)就會(huì)發(fā)現(xiàn)不能直接進(jìn)入雙擊操作禀晓。下面是區(qū)分 touch 事件是單擊還是雙擊的方法
-(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;//自己根據(jù)需要調(diào)整
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;
}
}
?```