如何让imageView响应点击操作

2024-12-28 03:27:20
推荐回答(2个)
回答1:

代码如下:
UIImageView *imageView = [self getYourImageView];
imageView.image = [self getYourImage];
imageView.userInteractionEnabled = YES;
UITapGestureRecognizer *singleTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(yourHandlingCode:)];
[imageView addGestureRecognizer:singleTap];
[singleTap release];

回答2:

UIImageView *imageView = [self getYourImageView];
imageView.image = [self getYourImage];
imageView.userInteractionEnabled = YES;
UITapGestureRecognizer *singleTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(yourHandlingCode:)];
[imageView addGestureRecognizer:singleTap];
[singleTap release];