1

tapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@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 和 tap==2 的时间呢?在我的代码中可以识别双击,但我不确定在找到单击时如何查找和工作。

谢谢

4

2 回答 2

2

这可能会给 ua soln

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
于 2013-03-15T05:15:51.730 回答
0

以下似乎是一篇关于 iOS 触摸的好文章。

http://www.sitepen.com/blog/2008/07/10/touching-and-gesturing-on-the-iphone/

于 2013-03-15T05:12:55.910 回答