Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UITapGestureRecognizer in UIScrollView subview

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.

like image 479
brainondev Avatar asked Mar 19 '11 18:03

brainondev


1 Answers

I've enabled the userInteraction for imageView and also the canCancelContentTouches option for the scrollView:

[imageScrollView setCanCancelContentTouches:YES];
[imageView setUserInteractionEnabled:YES];

It works now.

like image 140
brainondev Avatar answered Sep 20 '22 13:09

brainondev