0

I have two IBActions applied to a button one of which fires on touchdown and down and the other on touch up, however I also have a tap gesture applied to the button that fires on a double tap.

I've applied NSLog to see whats happening and the result is that both the touchdown and double tap fire when I double tap (fortunately the touch up doesn't fire) which makes sense - but how do i prevent the touch down firing when I double tap?

Code example

//fired on touch down 
-(IBAction)touchdown:(id)sender
{
    NSLog(@"touching down.");
}

//fired on touch up
-(IBAction)touchup:(id)sender
{   
    NSLog(@"taking off.");
}

//fired on double click
-(IBAction)boost:(UITapGestureRecognizer *)sender
{
    NSLog(@"goodbye.");
}
Nirav Gadhiya
  • 6,342
  • 2
  • 37
  • 76

1 Answers1

0

Import the delegate, <UIGestureRecognizerDelegate>

I think you done this in viewDidLoad Method,

UITapGestureRecognizer *tapGestureRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(boost:)];
tapGestureRecognizer.delegate = self;
tapGestureRecognizer.numberOfTapsRequired = 2;
[self.button addGestureRecognizer:tapGestureRecognizer];

You need to implement this delegate method, based on your touch down coordinates,

  -(BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch
    {
        CGPoint coords = [touch locationInView:self.button];
        NSLog(@"Coords: %g, %g", coords.x, coords.y);
        if (coords.y < 21 && coords.y > 25)
           return NO;
        else
           return YES;
    }
karthika
  • 4,085
  • 3
  • 21
  • 23