Not sure what the exact reason is, but UIAlertView somehow makes the gesture shoot again. The workaround is to perform the show outside of the gesture handler using the performSelector function:
-(void) handleTapGesture:(UIGestureRecognizer *) sender { CGPoint tapPoint = [sender locationInView:imageView]; int tapX = (int) tapPoint.x; int tapY = (int) tapPoint.y; NSLog(@"TAPPED X:%d Y:%d", tapX, tapY); [self performSelector:@selector(showMessage) withObject:nil afterDelay:0.0]; } - (void)showMessage { UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Hello" message:@"How are you?" delegate:nil cancelButtonTitle:@"I'm awesome." otherButtonTitles:nil]; [alert show]; [alert release]; }
Edit:
The sign of gesture recognition passes through different states in the gesture (Start, Changed, etc.), and it calls the handler method every time the state changes. Therefore, the best and probably the right decision is to check the state recognition property of the gesture recognizer at the top of the handler:
-(void) handleTapGesture:(UIGestureRecognizer *) sender { if (sender.state != UIGestureRecognizerStateEnded) // <--- return; // <--- CGPoint tapPoint = [sender locationInView:imageView]; int tapX = (int) tapPoint.x; int tapY = (int) tapPoint.y; NSLog(@"TAPPED X:%d Y:%d", tapX, tapY); UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Hello" message:@"How are you?" delegate:nil cancelButtonTitle:@"I'm awesome." otherButtonTitles:nil]; [alert show]; [alert release]; }
source share