iphone - 检测 uiscrollview 内 uiimageview 中的点击

标签 iphone sdk uiimageview

我有一个 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/

相关文章:

java - 安卓框架?

iphone - 如何在 iOS 应用程序中嵌入配置文件

iphone - 在应用内购买多次要求输入密码

android - 如何关闭来电的媒体服务?我的 AudioManager 不工作

bash - 如何解决Android Studio问题?

ios - Swift 在转换色调后恢复原始图像颜色

ios - 从 ViewController 到 UIImageView 的 photoImageView 导出无效。 socket 不能连接到重复的内容

android - 获取 GridView 项目的图像名称

iphone - 游戏套件点对点

iphone - 如何获得用户对使用位置信息的持续同意