【问题标题】:Click Event on UIImageView programmatically以编程方式单击 UIImageView 上的事件
【发布时间】:2014-05-12 11:02:13
【问题描述】:
我正在显示来自代码的图像集合,
这是我的代码:
UIImageView *addview;
myimgeview *addimageview =[[myimgeview alloc]initWithImage:[UIImage imageNamed:[NSString stringWithFormat:@"%@%d",PhotoName,i]] text:[textArray objectAtIndex:i]];
我想以编程方式处理addimageView 上的触摸事件。
【问题讨论】:
标签:
objective-c
ios7
uiimageview
【解决方案1】:
我会建议不同的方法。将点击手势识别器添加到图像视图。这可能是最简单的解决方案。如果你有 addImageView 方法来添加图像视图,那么继续这样,
- (void)addImageView
{
UIImageView * imageView = [[UIImageView alloc] initWithFrame:CGRectMake(10,10,100,100);
imageView.userInteractionEnabled = YES;
UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self selector:@selector(tapped:)];
[imageView addGestureRecognizer:tap];
}
- (void)tapped:(UITapGestureRecognizer*)tap
{
NSLog(@"%@", tap.view);
}