iphone - 在主uiview的 subview 上获取点击事件

标签 iphone objective-c ios uiview uiscrollview

我有一个包含滚动图像 + 分页的 View 。我已将这些图像添加到 UIVIEW 上,并将此 UIView 添加到主视图。我想在 ScrollView 中检测图像上的点击事件并在主视图中处理它们。

我该怎么做?

请帮忙

最佳答案

你可以用手势识别器解决这个问题。

// In the view controller where you create the subviews
// (not sure from your question, but I think you are adding image views to a scroll view

UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake...];
UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(imageViewTapped:)];
[imageView addGestureRecognizer:tap];

现在,这将在 ImageView 被点击时被调用

- (void)imageViewTapped:(UITapGestureRecognizer *)gr {

    UIImageView *theImageViewThatGotTapped = (UIImageView *)gr.view;
}

关于iphone - 在主uiview的 subview 上获取点击事件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9985927/

相关文章:

objective-c - 分配/初始化 View 、添加到 subview 和返回的正确内存管理模式

objective-c - 为什么委托(delegate)中需要一些方法?

ios - 带有静态单元格的 UITableViewController 显示为空白

iphone - 如何用字符串唯一标识nsmanagementobject?

objective-c - 如何像数据库一样将值存储在 NSUserDefaults 中?

ios - 如何防止 Xcode/Interface Builder 自动向下移动 View ?

ios - 动态调整 xib 大小

iphone - 任何简单的 VAD 实现?

iphone - 使用新数据重新加载 Collection View

objective-c - 从单独的源文件关闭一个源文件中的面板