0

Heres the code where im adding the gesture recognizers

    UIImage *img = [UIImage imageWithContentsOfFile:media.thumbnailPath];
    UIImageView *imageView = [[UIImageView alloc] init];  
    imageView.image = img;  
    imageView.contentMode = UIViewContentModeScaleToFill;
    imageView.backgroundColor =[UIColor blackColor];  

    //Add tap guesture
    UITapGestureRecognizer *singleTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleSingleTap:)];
    UITapGestureRecognizer *doubleTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleDoubleTap:)];

    [singleTap setNumberOfTapsRequired:1];
    [singleTap setDelegate:self];

    [doubleTap setNumberOfTapsRequired:2];
    [doubleTap setDelegate:self];

    [singleTap requireGestureRecognizerToFail:doubleTap];

    [imageView addGestureRecognizer:singleTap];
    [imageView addGestureRecognizer:doubleTap];
    [singleTap release];
    [doubleTap release];

and i have implemented the

- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer
{
     NSLog(@"Gesturing");
     return YES;
}

but the delegate method is not called when dealing with the singletap gesture but it works for doubletap gesture

Aatish Molasi
  • 2,138
  • 3
  • 20
  • 43

2 Answers2

3

Check out Simultaneous gesture recognizers in Iphone SDK

For most cases you don't need to:

setup a delegate
permit simultaneous gesture recognition (unless you want simultaneous swipes; not likely)

Setting Gesture Recognizers

UITapGestureRecognizer *singleTap = [[UITapGestureRecognizer alloc] 
                                     initWithTarget:self 
                                     action:@selector(handleSingleTapOnMainImageView:)];

[imageView addGestureRecognizer:singleTap];
[singleTap release];

UITapGestureRecognizer *doubleTap = [[UITapGestureRecognizer alloc] 
                                     initWithTarget:self 
                                     action:@selector(handleDoubleTapOnMainImageView:)];
[doubleTap setNumberOfTapsRequired:2];
[singleTap requireGestureRecognizerToFail:doubleTap];
[imageView addGestureRecognizer:doubleTap];
[doubleTap release];

Method implementation

-(void)handleSingleTapOnMainImageView:(UIGestureRecognizer*)gestureView
{
NSLog(@"handleSingleTapOnMainImageView");
}

-(void)handleDoubleTapOnMainImageView:(UIGestureRecognizer*)gestureView
{
NSLog(@"handleDoubleTapOnMainImageView");
}
Community
  • 1
  • 1
Warif Akhand Rishi
  • 23,920
  • 8
  • 80
  • 107
-1

add imageView.userInteractionEnabled = YES; would be work!

Bhavin Bhadani
  • 22,224
  • 10
  • 78
  • 108