iOS touch事件单击双击区分响应
如果您的 iPhone 應用里有個 view,既有單擊操作又有雙擊操作。用戶雙擊 view 時,總是先執行一遍單擊的操作再執行雙擊的操作。所以直接判斷時就會發現不能直接進入雙擊操作。下面是區分 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;//自己根據需要調整
????
?? 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;
?? }
}
轉載于:https://www.cnblogs.com/xiaopin/p/6010776.html
總結
以上是生活随笔為你收集整理的iOS touch事件单击双击区分响应的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: python编程财务应用_Python笔
- 下一篇: 给图片加一层半透明_PPT小技巧——图片