定义Image的对象
- 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];
响应方法
- -(void)onClickImage{
- NSLog(@"图片被点击!");
- }