ITeye博客

iphone 处理单击和双击Touch

wanglei0119 · 2010-09-24 00:40 · iPhone · 移动开发 · Markdown

如果以不同的方式响应单击和双击事件时,就会出现复杂的情况。那么如何知道一个单击不是另一个双击的起始部分呢?一下代码可以用来处理处理这种情况:

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

评论(0)

暂无评论。

评论功能维护中,当前仅展示历史评论。