iOS development-3 confusing attributes for gestures

Source: Internet
Author: User

3 Confusing attributes for gestures

/**

 *   This section describes Tap of the 3 an attribute that is less Lin Qing and easily confused:

cancelstouchesinview/delaystouchesbegan/delaystouchesended

* (0) the first thing to know is

        1. this 3 gesturerecognizers ( gesture recognition 3

2. for touch events,window will only have one control to receive touch. This control is a control that touches touch first and overrides the Touch event method (one can)

3. gesture recognition and touch events are two separate things that can only be affected by these 3 properties and not be confused.

 *  (1)By default (that is, the3property is in the default value), if you touch awindow, first bywindowThe first control that meets the criteria(the control is written ashit-test View)receive theTouchand trigger Touch eventsTouchesbegan. At the same time, if a control's gesture recognizer receives theTouch, it will be identified. Send touch events After successful gesture recognitiontouchescancelledGiveHit-testview,hit-test Viewno longer respondingTouch.

* (2) Cancelstouchesinview:

     yes, In this case when the gesture recognizer recognizes the touch is sent touchescancelled hit-testview hit-test View touch touch

When set to no , the gesture recognizer does not send touchescancelled after it recognizes touch For hit-test, both the gesture recognizer and hit-test view respond to touch.

* (3) Delaystouchesbegan:

    default isNOThis case occurs when aTouch, the gesture recognizer first snaps to theTouch, and then sendHit-testview, the two respond to each other. If set toYES, the gesture recognizer is in the process of recognition (note that the identification process) and does notTouchsent tohit-test View, i.e.Hit-testviewthere will be no touch events. Only after the recognition fails will theTouchsent toHit-testview, in this casehit-test ViewThe response is delayed by about0.15ms.

* (4) delaystouchesended:

    default isYES. This situation occurs when aTouchwhen the gesture recognition is successful,sent totouchescancelledMessage toHit-testview, when gesture recognition fails, it will delay the approximate0.15ms,during the period of not receiving otherTouchbefore it is senttouchesended. If set toNOis not delayed, it is immediately senttouchesendedto end the current touch.

*/

The demo code is as follows, the reader self-copy attempts

Myviw inherited from UIView:

#import "MyView.h" @implementation myview-(void) Touchesbegan: (Nsset *) touches withevent: (uievent *) event{    NSLog ( @ "__begin");} -(void) touchescancelled: (Nsset *) touches withevent: (uievent *) event{    NSLog (@ "__cancel");} -(void) touchesended: (Nsset *) touches withevent: (uievent *) event{    NSLog (@ "__end");} -(void) touchesmoved: (Nsset *) touches withevent: (uievent *) event{    NSLog (@ "__touch");} @end

#import "ViewController.h" #import "MyView.h" @interface Viewcontroller () @property (nonatomic, strong) MyView *myview;@    End@implementation viewcontroller-(void) viewdidload {[Super viewdidload];    _myview = [[MyView alloc]initwithframe:cgrectmake ([UIScreen mainscreen].bounds.size.width-100, 200)];    _myview.backgroundcolor = [Uicolor Yellowcolor];    [Self.view Addsubview:_myview];    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initwithtarget:self Action: @selector (tapaction:)];    tap.numberoftapsrequired = 2;   [_myview Addgesturerecognizer:tap]; }-(void) Tapaction: (UITapGestureRecognizer *) tap{NSLog (@ "click");}-(void) Touchesbegan: (Nsset *) touches withevent: ( Uievent *) event{NSLog (@ "Begin");} -(void) touchescancelled: (Nsset *) touches withevent: (uievent *) event{NSLog (@ "Cancel");}-(void) touchesended: (Nsset * ) Touches withevent: (uievent *) event{NSLog (@ "End");} -(void) touchesmoved: (Nsset *) touches withevent: (uievent *) event{NSLog (@ "Touch");} @end

iOS Development-3 confusing properties for 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.