Ios adds gestures to ImageView no response

Source: Internet
Author: User

The truth is similar, simple write, is to UIImage where the Uiimageview add a click of the gesture, let the user click on the picture responds to the response.

Some people use a transparent uibutton, feeling sometimes inconvenient.

-(void) viewdidload

{

Uiimageview *imageview = [[Uiimageview alloc]initwithframe:cgrectmake (0, 0, 200, 200)];

imageview.userinteractionenabled = YES;

UITapGestureRecognizer *singletap =

[[UITapGestureRecognizer alloc]initwithtarget:self Action: @selector (Whenclickimage)];

[ImageView Addgesturerecognizer:singletap];

[ImageView setimage:[uiimage imagenamed:@ "1.png"];

[Singletap release];

[Self.view Addsubview:imageview];

}

-(void) whenclickimage

{

NSLog (@ "You click image");

}

Not only Uiimageview can be added, Uiscrollview can also be. You can also add other gestures such as double-tap rotation.

Relatively simple and practical.

Original address: http://blog.sina.com.cn/s/blog_6f453dd601016idd.html

Ios adds gestures to ImageView no response

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.