iOS UIImageView图片添加点击事件

版权声明:本文为博主原创文章,欢迎转载,但是请注明原地址 https://blog.csdn.net/icefishlily/article/details/60571837

其实很简单,用的就是UITapGestureRecognizer,但是UIImageView的userInteractionEnabled属性默认是NO,对,你没看错,NO!!!

所以要把这个参数设置成YES。亲测管用,上代码:

    UIImage *img = [UIImage imageWithContentsOfFile:@"/Users/jinhui005/Desktop/style_img.png"];
    UIImageView *imgView = [[UIImageView alloc] initWithImage:img];
    UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(clickImage)];
    [imgView addGestureRecognizer:tapGesture];
    imgView.userInteractionEnabled = YES;


阅读更多
想对作者说点什么? 我来说一句

没有更多推荐了,返回首页