1 UIImageView *imgView =[[UIImageView alloc] initWithFrame:CGRectMake(128, 80,64,64)];
2 imgView.image = [UIImage imageNamed:@"portrait.png"];
3 imgView.userInteractionEnabled=YES;
4 UITapGestureRecognizer *singleTap =[[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(onClickPortraitImage)];
5 [imgView addGestureRecognizer:singleTap];
6 [self.view addSubview:imgView];
3 imgView.userInteractionEnabled=YES;
4 UITapGestureRecognizer *singleTap =[[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(onClickPortraitImage)];
5 [imgView addGestureRecognizer:singleTap];
6 [self.view addSubview:imgView];
2、响应点击事件
1 -(
void)onClickPortraitImage{
2
3 NSLog(@"图片被点击!");
4 }
2
3 NSLog(@"图片被点击!");
4 }
开发工具Xcode5 系统版本:
OS X 10. 9. 3 ( 13D65 )