`

新风作浪博客学习(十七)UIImageView响应点击事件 .

    博客分类:
  • ios
 
阅读更多
有时候会遇到点击一张图片,然后让这张图片触发一个事件,或者是跳转视图,想到的第一个方法就是用UIButton,将Button的背景图片属性设置为该图片,效果达到了,但不是最好的方法,直接触发方法

定义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(@"图片被点击!");
}


参考:http://www.cocoachina.com/bbs/read.php?tid=73570&page=3


分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics