读书人

iphone 处理单击跟双击Touch

发布时间: 2012-09-20 09:36:50 作者: rapoo

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


读书人网 >Iphone

热点推荐