I'm trying to use a single tap recognizer in an imageView (that is also a scrollView child). In Interface Builder I've created and referentiated the scrollView only. Works the scrolling but the single tap event is not recognized (nothing is logged). Here's the code:
- (void)loadView {
[super loadView];
UIImage *myImage = [UIImage imageNamed:@"img1.jpg"];
imageView = [[UIImageView alloc] initWithImage:myImage];
[myImage release];
// add gesture recognizers to the image view
UITapGestureRecognizer *singleTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleSingleTap:)];
[imageView addGestureRecognizer:singleTap];
[singleTap release];
[imageScrollView setContentSize:CGSizeMake(imageView.frame.size.width, imageView.frame.size.height)];
[imageScrollView addSubview:imageView]; }
- (void)handleSingleTap:(UIGestureRecognizer *)gestureRecognizer {
// single tap handling
NSLog(@"sinlgeTap called"); }
I've looked around for hours and tried many things. Maybe a look of someone else can help much more. Thanks.
I've enabled the userInteraction for imageView and also the canCancelContentTouches option for the scrollView:
[imageScrollView setCanCancelContentTouches:YES];
[imageView setUserInteractionEnabled:YES];
It works now.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With