I’m looking at Apple’s example code from the ScrollViewSuite. I must be doing something wrong in comparison. In their RootViewController, they do:
- (void)loadView {
[super loadView];
// set the tag for the image view
[imageView setTag:ZOOM_VIEW_TAG];
// add gesture recognizers to the image view
UITapGestureRecognizer *singleTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleSingleTap:)];
UITapGestureRecognizer *doubleTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleDoubleTap:)];
UITapGestureRecognizer *twoFingerTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleTwoFingerTap:)];
[doubleTap setNumberOfTapsRequired:2];
[twoFingerTap setNumberOfTouchesRequired:2];
[imageView addGestureRecognizer:singleTap];
[imageView addGestureRecognizer:doubleTap];
[imageView addGestureRecognizer:twoFingerTap];
[singleTap release];
[doubleTap release];
[twoFingerTap release];
// calculate minimum scale to perfectly fit image width, and begin at that scale
float minimumScale = [imageScrollView frame].size.width / [imageView frame].size.width;
[imageScrollView setMinimumZoomScale:minimumScale];
[imageScrollView setZoomScale:minimumScale];
}
In IB, they have their imageView as a subView of the imageScrollView. My .xib is set up the same way. I put this code in my viewDidLoad instead of loadView. I do not get any calls when I double tap on my imageView. I’m wondering why. Here is my version of what they did:
- (void)viewDidLoad {
[self updateOnScreenImages]; // this is where my imageView.image property gets set
UITapGestureRecognizer *doubleTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleDoubleTap:)];
doubleTap.numberOfTapsRequired = 2;
UITapGestureRecognizer *twoFingerTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleTwoFingerTap:)];
[doubleTap setNumberOfTouchesRequired:2];
[self.imageView addGestureRecognizer:doubleTap];
[self.imageView addGestureRecognizer:twoFingerTap];
[doubleTap release];
[twoFingerTap release];
}
Is there something I am doing wrong compared to what Apple is doing? The logic seems pretty similar to me. But I’m not getting my callbacks when I double tap. I tried adding the gestures to the self.scrollView as well, but that doesn’t work either. Thoughts? Thanks!
Try to add:
by default
UIImageViews have that property set toNO(apple may have changed it in XIB file, and you may have lost that…)