The light point of gesture recognition

Source: Internet
Author: User

#import "ViewController.h" @interface Viewcontroller () @property (nonatomic,strong) Uiimageview *imgview;@    End@implementation viewcontroller-(void) viewdidload {[Super viewdidload]; Self.    Imgview=[[uiimageview alloc]initwithimage:[uiimage imagenamed:@ "Img.jpg"]; Self.    imgview.tag=10001; Self.    Imgview.frame=cgrectmake (100, 100, 100, 100); Uiimageview default does not support user interaction change to Yes self.    Imgview.userinteractionenabled=yes; Tap, Pinch,pan, swipe is just a simple single touch, in order to achieve multi-touch, need to set multipletouchenabled support multi-touch self.    Imgview.multipletouchenabled=yes; Instantiate the recognition object and register the Listener method UITapGestureRecognizer *singletap=[[uitapgesturerecognizer alloc]initwithtarget:self action:@    Selector (SIGNALTAP:)]; [Self.    Imgview Addgesturerecognizer:singletap];    Number of clicks required default 1 singletap.numberoftapsrequired=1;    At the same time click on the number of fingers default 1 in the simulator to simulate a number of finger test needs in the real machine singletap.numberoftouchesrequired=2;    Set proxy singletap.delegate=self; [Self.view addsubview:self.        Imgview]; UITapGestureRecognizer *doubletap=[[uitapgesturerecOgnizer alloc]initwithtarget:self Action: @selector (Signaltap:)];    doubletap.numberoftapsrequired=2;    doubletap.numberoftouchesrequired=1;    doubletap.delegate=self; [Self.    Imgview Addgesturerecognizer:doubletap];    Two finger click once and one finger click Two user click unclear may confuse [Singletap Requiregesturerecognizertofail:doubletap];    }-(void) Signaltap: (Uigesturerecognizer *) gesturerecognizer{//Get click View UIView *view=gesturerecognizer.view;    NSLog (@ "%ld", View.tag); The state is an enumeration type//uigesturerecognizerstatepossible,//uigesturerecognizerstatebegan,//uigesturerecognizerstatechanged ,//uigesturerecognizerstateended, normally only responds to this one//uigesturerecognizerstatecancelled,//Uigesturerecognizerstatefaile d,//uigesturerecognizerstaterecognized = uigesturerecognizerstateended NSLog (@ "gesture Status:%ld", gesturerecognizer.state)    ; NSLog (@ "Light point");} Ask if a gesture recipient should start performing a touch receive event-(BOOL) Gesturerecognizershouldbegin: (Uigesturerecognizer *) gesturerecognizer{// Specifies the region of the response Cgpoint Currentpoint=[gesturerecognizeR LocationInView:self.view];    if (Cgrectcontainspoint (CGRectMake (+,-), Currentpoint)) {return YES; } return NO; Ask delegate, whether two gestures receive messages at the same time, return yes to receive simultaneously. Return no, do not receive at the same time, the default no//that is two gesture recognizers delegate method as long as any one return yes, the two can be recognized at the same time-(BOOL) Gesturerecognizer: ( Uigesturerecognizer *) Gesturerecognizer Shouldrecognizesimultaneouslywithgesturerecognizer: (UIGestureRecognizer *    ) othergesturerecognizer{NSLog (@ "identification"); return NO;} In the early stages of a gesture life cycle, when all gesture recognition in a view is still processing the possible state, then in iOS 7 Gesturerecognizer:shouldrequirefailureofgesturerecognizer: and Gesturerecognizer:shouldberequiredtofailbygesturerecognizer: Messages are sent to all of these gesture recognition delegates to match the gesture recognition in this view. Returns YES to prioritize this two incoming gestures, which means that the gesture recognition succeeds when another gesture recognition fails. Essentially, these delegate methods take the returned result as a one-and-a-permanent decision, making it more real-time when each gesture occurs. (This is not quite understood)-(BOOL) Gesturerecognizer: (Uigesturerecognizer *) Gesturerecognizer Shouldrequirefailureofgesturerecognizer: (Uigesturerecognizer *) othergesturerecognizer{return NO;} -(BOOL) Gesturerecognizer: (Uigesturerecognizer *) Gesturerecognizer ShoulDberequiredtofailbygesturerecognizer: (Uigesturerecognizer *) othergesturerecognizer{return NO;} Before Touchebegan this method, that is, before the gesture state is began. This method is called before the Window object invokes the Touchesbegan:withevent: method of gesture recognizer when a touch event occurs. If no is returned, gesture recognizer will not see this touch event. (yes by default).-(BOOL) Gesturerecognizer: (Uigesturerecognizer *) Gesturerecognizer Shouldreceivetouch: (Uitouch *) touch {return YES;} -(void) didreceivememorywarning {[Super didreceivememorywarning];} @end

a gesture recognizer is not involved in the UIView event response chain

The light point of gesture recognition

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.