tapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self 动作:@selector(handleTapGesture :)]; tapGesture.numberOfTapsRequired = 2; tapGesture.numberOfTouchesRequired = 1;
[self.view addGestureRecognizer:tapGesture]; [tapGesture release];
和
- (void)handleTapGesture:(UITapGestureRecognizer *)sender {
if (sender.state == UIGestureRecognizerStateRecognized) {
// handling code
NSLog(@"We got double tap here");
DashBoardViewController* dashboardObj = [[DashBoardViewController alloc] initWithNibName:@"DashBoardViewController" bundle:nil];
[self.navigationController pushViewController:dashboardObj animated:YES];
}
我想要做的是,我想在单击和双击时调用2个不同的事件。 那么我怎样才能检测到tap == 1并点击== 2? 双击在我的代码中被识别,但我不确定,如何找到并工作,只需点击一下。
由于
答案 0 :(得分:2)
这可能会给你一个解决方案
UITapGestureRecognizer *singleTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleSingleTap:)];
UITapGestureRecognizer *doubleTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleDoubleTap:)];
[doubleTap setNumberOfTapsRequired:2];
[singleTap setNumberOfTouchesRequired:1];
[self.view addGestureRecognizer:singleTap];
[self.view addGestureRecognizer:doubleTap];
- (void)handleSingleTap:(UIGestureRecognizer *)gestureRecognizer {
// single tap action
}
- (void)handleDoubleTap:(UIGestureRecognizer *)gestureRecognizer {
// double tap action
}
或者你必须使用NSTimer,因为darren指出要验证单次触摸。
在方法中,
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
答案 1 :(得分:0)
关于iOS中的触摸似乎是一篇很好的帖子。
http://www.sitepen.com/blog/2008/07/10/touching-and-gesturing-on-the-iphone/