如果您的 iPhone 應(yīng)用里有個 view,既有單擊操作又有雙擊操作。用戶雙擊 view 時,總是先執(zhí)行一遍單擊的操作再執(zhí)行雙擊的操作。所以直接判斷時就會發(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;}}以上所述是小編給大家介紹的iOS touch事件區(qū)分單擊雙擊響應(yīng)的方法,希望對大家有所幫助,如果大家有任何疑問歡迎給我留言,小編會及時回復(fù)大家的!
新聞熱點(diǎn)
疑難解答
圖片精選