首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 移动开发 > Iphone >

iphone 处理单击跟双击Touch

2012-09-20 
iphone 处理单击和双击Touch如果以不同的方式响应单击和双击事件时,就会出现复杂的情况。那么如何知道一个

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];    }}


热点排行