views:

27

answers:

1

Hi

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

+2  A: 

Make sure userInteractionEnabled is set to YES on the UIImageView:

frame.userInteractionEnabled = YES;

I'd also recommend using a different name for the UIImageView variable (eg. imageView instead of frame). Otherwise, you can easily confuse it with the view's frame property.

aBitObvious
Thanks! That made the trick.
Jorge