当前位置: 代码迷 >> Iphone >> iphone 处理单击跟双击Touch
  详细解决方案

iphone 处理单击跟双击Touch

热度:38   发布时间:2016-04-25 06:24:59.0
iphone 处理单击和双击Touch
如果以不同的方式响应单击和双击事件时,就会出现复杂的情况。那么如何知道一个单击不是另一个双击的起始部分呢?一下代码可以用来处理处理这种情况:

在你的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];    }}


  相关解决方案