因为做聊天APP的时候,imageView会作为气泡图使用
点击它会有一系列事件,因此想到了如下的方法.
1.定义imageView对象
UIImageView *imgView =[[UIImageView alloc] initWithFrame:CGRectMake(0, 0,320,100)];
imgView.backgroundColor = [UIColor redColor];//因为没有设置image属性,为了显示出图片覆盖区域
imgView.userInteractionEnabled=YES;
UITapGestureRecognizer *singleTap =[[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(onClickImage)];
[imgView addGestureRecognizer:singleTap];
[singleTap release];
2.触发事件
-(void)onClickImage{
NSLog(@"图片被点击!");
}