如果以不同的方式响应单击和双击事件时,就会出现复杂的情况。那么如何知道一个单击不是另一个双击的起始部分呢?一下代码可以用来处理处理这种情况:
在你的UIView或UIViewController里重载touchesBegan和touchesEnded方法:
在你的UIView或UIViewController里重载touchesBegan和touchesEnded方法:
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
UITouch *touch = [touches anyObject];
if ([touch tapCount] == 2) {
[NSObject cancelPreviousPerformRequestsWithTarget:self];
} else {
[self performSelector:@selector(testSingleTouch:) withObject:touch afterDelay:0.5f];
}
}
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
UITouch *touch = [touches anyObject];
if ([touch tapCount] == 2) {
[self testMultipleTouch];
}
}