我有一个 UIScrollView,其中包含多个 UIImageView,如下创建。
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];
问题是点击图像时不会调用 imageTapped。
如果我将手势识别器添加到 ScrollView ,如下所示:
UITapGestureRecognizer *tap =
[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(imageTapped:)];
[scroll addGestureRecognizer:tap];
[tap release];
调用 imageTapped。
如何检测 UIImageView 上的点击?
谢谢
最佳答案
确保 UIImageView 上的 userInteractionEnabled 设置为 YES:
frame.userInteractionEnabled = YES;
我还建议为 UIImageView 变量使用不同的名称(例如,使用 imageView 而不是框架)。否则,您很容易将其与 View 的框架属性混淆。
关于iphone - 检测 uiscrollview 内 uiimageview 中的点击,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4023991/