开发者

Click an UIImage and open an UIImageView in Objective-c

开发者 https://www.devze.com 2023-04-08 23:58 出处:网络
Suppose I have an UiImage called \"thumbnail\" on a view, I want to ask how to open an UiImageView when I click on the UiImage(thumbnail)?

Suppose I have an UiImage called "thumbnail" on a view, I want to ask how to open an UiImageView when I click on the UiImage(thumbnail)?

This effect is similar to an user click on a small image on a webpage, t开发者_运维技巧hen popup a larger image.

Thanks


Add UITapGestureRecognizer to your UIImageView:

UITapGestureRecognizer *tapRecognizer;
tapRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(yourSelector)];
[thumbnail addGestureRecognizer:tapRecognizer];
[tapRecognizer release];

thumbnail.userInteractionEnabled = YES; // very important for UIImageView


A UIImage can't exist "on a view" as it is just a representation of some image data. So you'd have an appropriately sized and shaped UIButton, with your thumbnail image as it's image, and link this button's action to the creating and presenting of a new UIImageView.


I would suggest you rather use a UIButton and set its Background image to your image. Then you can wire an IBAction from this button to your view controller.

0

精彩评论

暂无评论...
验证码 换一张
取 消