A long tap gesture is called twice when a warning is displayed.

I have problems with a long press gesture here. I looked around and found some post related to my problems, but still no luck.

I have a long gesture for the presentation for the presentation, and I want to show the warning view when the gesture is a trigger, but somehow the trigger was called twice when the warning view is displayed, I check the status of the gestures but still no luck. Here is the code:

Source:

UILongPressGestureRecognizer *longTap = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(handleTapGesture:)];

[longTap setMinimumPressDuration:1];
[self addGestureRecognizer:longTap];


- (IBAction)handleTapGesture:(UIPanGestureRecognizer*)sender {
if (sender.state == UIGestureRecognizerStateChanged) {
NSLog(@"Change");
} else if (sender.state == UIGestureRecognizerStateEnded) {
NSLog(@"Ended");
}
else {
NSLog(@"Begin");
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Long pressed" message:nil delegate:nil cancelButtonTitle:@"OK" otherButtonTitles: nil];
[alert show]; //If I remove this line, the trigger is call only once. 
}
}

The strangest thing is, if I delete [warning show], everything will go as expected, the trigger gesture only once. Does anyone have an explanation? Thanks in advance.

+4
source share
1

, .

UILongPressGestureRecognizer *longTap = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(handleTapGesture:)];
[longTap setMinimumPressDuration:1];
longTap.delegate = (id)self;
[self.view addGestureRecognizer:longTap];


- (void)handleTapGesture:(UILongPressGestureRecognizer *)sender
{
    if (sender.state == UIGestureRecognizerStateChanged)
    {
        NSLog(@"Change");
    }
    else if (sender.state == UIGestureRecognizerStateEnded)
    {
        NSLog(@"Ended");
    }
    else if (sender.state == UIGestureRecognizerStateBegan)
    {
        NSLog(@"Begin");
        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Long pressed" message:nil delegate:nil cancelButtonTitle:@"OK" otherButtonTitles: nil];
        [alert show]; //If I remove this line, the trigger is call only once.
    }
}
+5

All Articles