uiview-the difference between double-tap gestures and click gestures

Source: Internet
Author: User

The practice of recognizing double-click events in iOS:

    1. Create the UITapGestureRecognizer object, set the value of numberoftapsrequired to 2,
UITapGestureRecognizer *doubletaprecognizer =            [[UITapGestureRecognizer alloc] initwithtarget:self                                                    Action: @selector (Doubletap:)];         2 ;        [Self addgesturerecognizer:doubletaprecognizer];

    1. Action function

  -(void) Doubletap: (Uigesturerecognizer *) gr   {       NSLog (@ "recognized Double TAP ");   }

The Touchesbegan function is implemented in the same uiview

// Touch Start -(void) Touchesbegan: (Nsset *) touches withevent: (uievent *)event{    NSLog (@ "touch begin"); }


When you double-click, view the log. The order in which the touch events occurred is found below:

2015-09-15 21:57:55.249 touchtracker[20387:5622651] Touch begin

2015-09-15 21:57:55.421 touchtracker[20387:5622651] Double tap

This is because when the user taps the screen, UIView receives the message in Touchesbegan:withevent. UIView receives the touchesbegan:withevent message before the Uigesturerecognizer recognizes the double-click Gesture, and after the recognition Uigesturerecognizer recognizes the double-tap gesture, Uigesturerecognizer handles related touch events on its own, and uiresponder messages caused by touch events are no longer sent to UIView. UIView will not receive Uiresponder messages until Uigesturerecognizer detects that the tap gesture has ended.


you need to avoid sending touchbegin:withevent messages to UIView before you recognize a tap gesture. the Delaystouchesbegan value is set to Yes.

UITapGestureRecognizer * doubletaprecognizer=        [[UITapGestureRecognizer alloc]initwithtarget:self action:@ Selector (DOUBLETAP:)];        doubletaprecognizer.numberoftapsrequired=2;        Doubletaprecognizer.delaystouchesbegan=YES;         [Self addgesturerecognizer:doubletaprecognizer];
difference Double click and click

Add Single click Recognition

// Single tap          *taprecognizer=        [[UITapGestureRecognizer alloc]initwithtarget:self Action: @selector (tap:)] ;        [Self addgesturerecognizer:taprecognizer];action function -(void) Tap: (Uigesturerecognizer *) gr{    NSLog (@ "tap");}

When I looked at the log output, I found that when I clicked two times, UIView didn't recognize the Click event and the double click event. Tap: And Doubletap: Will execute.

2015-09-15 22:36:02.441 touchtracker[20631:5667414] Tap

2015-09-15 22:36:02.600 touchtracker[20631:5667414] Double tap

Because the double-click event contains two clicks, the first click is recognized as a click event.


Settings are temporarily not recognized after a click (a little pause) until you identify the click event after the event is not double-clicked.

// Single tap          *taprecognizer=        [[UITapGestureRecognizer alloc]initwithtarget:self Action: @selector (tap:)] ;        [Taprecognizer Requiregesturerecognizertofail:doubletaprecognizer];        [Self addgesturerecognizer:taprecognizer];

uiview-the difference between double-tap gestures and click gestures

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.