Gesture recognition of the iOS development gesture

Source: Internet
Author: User

#import "ViewController.h"@interfaceViewcontroller () <UIGestureRecognizerDelegate>@property (Weak, nonatomic) Iboutlet Uiimageview*Imagev;@end@implementationViewcontroller- (void) viewdidload {[Super viewdidload]; //1. Create gesturesUiswipegesturerecognizer *swipe =[[Uiswipegesturerecognizer alloc] initwithtarget:self action: @selector (swipe:)]; //set the direction of the swipe (a swipe gesture can only correspond to One direction)Swipe.direction =Uiswipegesturerecognizerdirectionleft; Uiswipegesturerecognizer*swipe1 =[[Uiswipegesturerecognizer alloc] initwithtarget:self action: @selector (swipe:)]; //set the direction of the swipe (a swipe gesture can only correspond to One direction)Swipe1.direction =Uiswipegesturerecognizerdirectionright; //2. Add gestures[Self.imagev Addgesturerecognizer:swipe]; [Self.imagev addgesturerecognizer:swipe1];}//called when swiping- (void) Swipe: (Uiswipegesturerecognizer *) swipe{if(Swipe.direction = =uiswipegesturerecognizerdirectionleft) {NSLog (@" Left"); }Else if(Swipe.direction = =uiswipegesturerecognizerdirectionright) {NSLog (@" Right"); }        //NSLog (@ "%s", __func__);}//long-Press gestures- (void) longp{//1. Create gesturesUilongpressgesturerecognizer *LONGP =[[Uilongpressgesturerecognizer alloc] initwithtarget:self action: @selector (LONGP:)]; //2. Add gestures[Self.imagev ADDGESTURERECOGNIZER:LONGP];}//called on a long-time basis (the method continues to be called when a long press is moved)- (void) LONGP: (Uilongpressgesturerecognizer *) longp{NSLog (@"%s", __func__); //judging the state of a gesture    if(Longp.state = =Uigesturerecognizerstatebegan) {NSLog (@"Start Long Press"); }Else if(Longp.state = =uigesturerecognizerstatechanged) {NSLog (@"move long and on time"); }Else if(Longp.state = =uigesturerecognizerstateended) {NSLog (@"Finger away"); }    }//Tap gestures- (void) setuptap{UITapGestureRecognizer*tap =[[UITapGestureRecognizer alloc] initwithtarget:self action: @selector (TAP)]; Tap.Delegate=Self ; //2. Add gestures[Self.imagev Addgesturerecognizer:tap]; }//3. Implement gesture Methods- (void) tap{NSLog (@"%s", __func__);}//whether to allow fingers to be received.//-(BOOL) Gesturerecognizer: (Uigesturerecognizer *) Gesturerecognizer Shouldreceivetouch: (Uitouch *) Touch {//let the current picture, left cannot click, right can click//gets the point of the current finger//cgpoint curp = [Touch LocationInView:self.imageV];//    //if (curp.x > Self.imageV.frame.size.width * 0.5) {//        //on the right .//return YES;//}else{//        //on the left//return NO;//    }//    ////}- (void) didreceivememorywarning {[Super didreceivememorywarning]; //Dispose of any resources the can be recreated.}@end

Gesture recognition of the iOS development gesture

Related Article

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.