IOS touch event click double-click to differentiate responses, iostouch
If your iPhone app has a view, you can click or double-click it. When you double-click a view, you always perform the double-click operation first. Therefore, you will find that you cannot directly double-click it. The following method is used to differentiate whether a touch event is clicked or double-clicked.
-(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; // adjust it as needed
Switch (touch. tapCount ){
Case 1:
[Self defined mselector: @ selector (singleTap) withObject: nil afterDelay: delaytime];
Break;
Case 2 :{
[NSObject cancelPreviousPerformRequestsWithTarget: self selector: @ selector (singleTap) object: nil];
[Self defined mselector: @ selector (doubleTap) withObject: nil afterDelay: delaytime];
}
Break;
Default:
Break;
}
}