Search code examples
iphoneiosgesturepinch

UIPinchGestureRecognizer not responding


I have a universal binary application and currently working on the iPad version of the application. The iPad is using a uitabbarcontroller and on the second tab I have 6 images and when adding a UIPinchGesture it is not responding. I have userInteractionEnabled=YES; I tried adding the image view programmatically and then adding the gesture recognizer and still nothing seems to work.

I tried setting the delegate to the view controller and implementing one of the delegate methods and didn't get any responses. Below is the code sample of what I am doing:

UIImageView *img2 = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"img2-large.png"]];
img2.frame = CGRectMake(20, 20, 100, 100);
[img2 setUserInteractionEnabled:YES];
img2.contentMode = UIViewContentModeScaleAspectFit;
[self.view addSubview:img2];    

UIPinchGestureRecognizer *img2Pinch = [[UIPinchGestureRecognizer alloc] initWithTarget:self action:@selector(img2Pinch:)];
[img2 addGestureRecognizer:img2Pinch];
[img2Pinch release];


- (void)img2Pinch:(UIPinchGestureRecognizer *)sender {
      NSLog(@"HERE");
}

I'm sure it's something silly that I'm missing. I've used this stuff before but can't for the life of me figure out what is going wrong.


Solution

  • Set userInteractionEnabled to YES. The default is NO. Also, in order to handle multi-touches, which is what the pinch is, multipleTouchEnabled needs to be set to YES.