Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Detecting taps in uiimageview inside uiscrollview

Tags:

I have a UIScrollView with multiple UIImageViews in it created like this.

frame = [[UIImageView alloc] initWithImage:bg];
frame.frame = CGRectMake(FRAME_SEPARATOR + numPage*1024 + numColumn*(FRAME_SEPARATOR+230), 10 +numRow*(FRAME_SEPARATOR+145), 230, 145);
UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(imageTapped:)];
[frame addGestureRecognizer:tap];
[tap release];
[scroll addSubView:frame];

The problem is that imageTapped is not being called when tapping over an image.

If I add the gesture recognizer to the scrollview like this:

UITapGestureRecognizer *tap =
[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(imageTapped:)];
[scroll addGestureRecognizer:tap];
[tap release];

imageTapped is called.

How can I detect the taps over the UIImageViews?

Thanks