IOS Controls Click Effect Gesture Effect UITapGestureRecognizer usage

Source: Internet
Author: User

UITapGestureRecognizer usage of the gesture effect when you need to add a click effect to a picture, icon, and other controls

Look directly at the code example:

-(void) viewdidload {    [super viewdidload];    Additional setup after loading the view, typically from a nib.    Uiimageview *imgview =[[uiimageview alloc] Initwithframe:cgrectmake (0, 0,320,100)];    Imgview.backgroundcolor = [Uicolor redcolor];    Because the Image property is not set, in order to display the image overlay area    Imgview.userinteractionenabled=yes;    UITapGestureRecognizer *singletap =[[uitapgesturerecognizer alloc]initwithtarget:self                                                                              action: @selector ( Onclickimage)];    [Imgview Addgesturerecognizer:singletap];    [Self.view Addsubview:imgview];}
Handling single-finger event-(void) Handlesinglefingerevent: (UITapGestureRecognizer *) sender{    if (sender.numberoftapsrequired = = 1) {        //single-Finger click        NSLog (@ "single finger click");    }    else if (sender.numberoftapsrequired = = 2) {        //single-finger double-click        NSLog (@ "single-finger double-click");}    } Handling two-finger events-(void) Handledoublefingerevent: (UITapGestureRecognizer *) Sender {    if (sender.numberoftapsrequired = = 1) {        //two-finger click        NSLog (@ "Two-finger click");    }    else if (sender.numberoftapsrequired = = 2) {        //double-fingered double-click        NSLog (@ "double-finger double-click");}    }

Gesture action to be added



IOS Controls Click Effect Gesture Effect UITapGestureRecognizer usage

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.