#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