How to consider only one gesture if i am tapping on two views at a time

45 Views Asked by At

I created one view inside my application in that again i created ten views like a grid and i added UITapGestureRecogniser on ten views,if the user tap on one of the view in grid i will call a method where based on its tag value I will create a new view instance of a particular class.But i am getting problem if the user taps on two views at a time or in the difference of fraction of seconds ,then that method is called two times .It is creating problem inside my application.i need solution for this i am not getting any solution what to do.Can any one know this handle please help me as soon as possible.

Thanks &Regards swathi

1

There are 1 best solutions below

0
On

I'd just create a boolean, thats set to NO in every method called by these views.

At the end of the method, set it to YES

-(void)view1tapped{
       BOOL shouldRecognizeTap = enabled;
       self.enabled = NO;
       if (shouldRecognizeTap){
               // do your stuff here
       }
       self.enabled = YES;
} 

-(void)view2tapped{
       BOOL shouldRecognizeTap = enabled;
       self.enabled = NO;
       if (shouldRecognizeTap){
               // do your stuff here
       }
       self.enabled = YES;
} 

Also, in your gestureRecognizer delegate method, I hope you are checking for recognizer state like this

-(void) handleTapGesture:(UIGestureRecognizer *) sender {
    if (sender.state != UIGestureRecognizerStateEnded)  // <---
        return;  

    sender.enabled = NO // (or disable all the other gesture recognizers).
    // do your stuff here   
    sender.enabled = YES;
}