我正在尝试开发一个包含一些图像的应用程序,所以我做了这样的事情:@property (nonatomic, retain) IBOutletCollection(UIImageView)NSArray* photos;
我正在填写这些UIImageView
数组:[self.photos[i] setImage:[UIImage imageWithData:data]];
现在,我需要执行 segue,这会将用户重定向到另一个 View ,即点击哪个图像。
例子 :
假设我有 20 张图片和 View ,如果用户点击第一张图片,那么他应该被重定向到查看,如果用户点击第二张,那么相同的 View 等等......
最佳答案
我喜欢在 UIImageView 上添加 mask 按钮以响应用户触摸,但请注意 UIImageView 的 userInteractionEnabled 是 NO
默认情况下。
下面是示例代码,实际上我们总是将按钮设置为透明。
CGRect imageRect = (CGRect){100, 100, 100, 100};
UIImageView *imageView = [[[UIImageView alloc] initWithFrame:imageRect] autorelease];
imageView.backgroundColor = [UIColor yellowColor];
[self.view addSubview:imageView];
imageView.userInteractionEnabled = YES;
UIButton *maskBtn = [UIButton buttonWithType:UIButtonTypeCustom];
maskBtn.frame = imageView.bounds;
maskBtn.backgroundColor = [UIColor redColor];
[maskBtn addTarget:self action:@selector(maskBtnDidClick:) forControlEvents:UIControlEventTouchUpInside];
[imageView addSubview:maskBtn];
关于iphone - 如何检测点击/单击 UIImageView?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14791494/