1
votes

tapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleTapGesture:)]; tapGesture.numberOfTapsRequired = 2; tapGesture.numberOfTouchesRequired = 1;

[self.view addGestureRecognizer:tapGesture];
[tapGesture release];

and

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

what i am trying to do is , i want to call 2 different events on single tap and on double tap. So how can i detect when tap==1 and tap==2? Double tap is recognised in my code, but i am not sure, how to find and work,when a single tap is find.

Thanks

2
You could use a timer. Start the timer when you get a tap. If the timer expires you know you need to act on a a single tap. If you get another tap before the timer expires, you know you are dealing with a double tap.D.C.
could you plz help me on that...?Shishir.bobby

2 Answers

2
votes

This may give u a 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
}

or u have to use NSTimer as darren pointed to validate the single touch.

In the method,

- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event