1. Click
UITapGestureRecognizer *tap=[[UITapGestureRecognizer alloc] initwithtarget:self action: @selector (click)]; //set the number of times you want to click now[Tap setnumberoftapsrequired:1]; //sets the number of fingers that currently need to trigger an event[Tap setnumberoftouchesrequired:2];//Set Current proxyTap.Delegate=Self ; [_view Addgesturerecognizer:tap];//Trigger Method- (void) click{NSLog (@"the current view is clicked! ");}
2. Long Press
Uilongpressgesturerecognizer * longpress=[[Uilongpressgesturerecognizer alloc] initwithtarget:self action:@ Selector (longpress)]; // sets the current long press minimum length of longpress.minimumpressduration=2; // set allowed range of moves [Longpress setallowablemovement:2]; [_view addgesturerecognizer:longpress]; // Trigger Method -(void) longpress{ NSLog (@ "");}
3. Swipe
Uiswipegesturerecognizer * swip=[[Uiswipegesturerecognizer alloc] initwithtarget:self action: @selector (Swipmethod)]; //towards the left .swip.direction=Uiswipegesturerecognizerdirectionleft; //towards the right .swip.direction=Uiswipegesturerecognizerdirectionright; //go up the direction.swip.direction=Uiswipegesturerecognizerdirectionup; //go down the direction .swip.direction=Uiswipegesturerecognizerdirectiondown; [_view ADDGESTURERECOGNIZER:SWIP]; //Trigger Method- (void) swipmethod{NSLog (@"Swipe Event Trigger! ");}
If a gesture involving more than 2 directions is best to add multiple Uiswipegesturerecognizer objects and set different orientations, do not use the symbol | To connect in the following way:
Swip.direction=uiswipegesturerecognizerdirectionleft | Uiswipegesturerecognizerdirectionright
4. Drag
First step: Add a View
_view=[[uiview Alloc] Initwithframe:cgrectmake ()];[ _view Setbackgroundcolor:[uicolor Redcolor]]; [Self.view Addsubview:_view];
Step Two: Add gestures
Uipangesturerecognizer *pan=[[Uipangesturerecognizer alloc] initwithtarget:self action: @selector (paned:)];[ _view Addgesturerecognizer:pan];
Step Three: implementation methods
-(void) paned: (Uipangesturerecognizer *) pan{ // Get the size of the move cgpoint point= [Pan TranslationInView:pan.view]; // Change the center point coordinates of a view Cgpoint points=_view.center; Points.x+ =point.x; Points.y+ =point.y; _view.center=points; // clear every time. Eliminate coordinate overlays [Pan Settranslation:cgpointzero InView:pan.view];}
5. Rotation
First step: Add a View
_view=[[uiview Alloc] Initwithframe:cgrectmake ()];[ _view Setbackgroundcolor:[uicolor Redcolor]]; [Self.view Addsubview:_view];
Step Two: Add gestures
Uirotationgesturerecognizer * roate=[[Uirotationgesturerecognizer alloc] initwithtarget:self action: @selector ( Rotate:)]; [_view addgesturerecognizer:roate];roate. delegate=self;
Step Three: implementation methods
-(void) Rotate: (Uirotationgesturerecognizer *) rote{ // get the degree of current rotation CGFloat rotation= rote.rotation; // Rotation through affine transformations _view.transform=cgaffinetransformrotate (_view.transform, rotation); // prevent rotation overlays need to clear 0 rote.rotation=0;}
6. Kneading
First step: Add a View
_view=[[uiview Alloc] Initwithframe:cgrectmake ()];[ _view Setbackgroundcolor:[uicolor Redcolor]]; [Self.view Addsubview:_view];
Step Two: Add gestures
Uipinchgesturerecognizer * pich=[[Uipinchgesturerecognizer alloc] initwithtarget:self action: @selector (piches:) ]; [_view Addgesturerecognizer:pich];p ich. delegate=self;
Step Three: implementation methods
-(void) Piches: (Uipinchgesturerecognizer *) pich{ // get proportional cgfloat scale =Pich.scale; // Scaling with affine transformations _view.transform=Cgaffinetransformscale (_view.transform, scale, scale); // prevent proportional overlays from needing to be set to 1 pich.scale=1;}
"Supplemental" Override proxy method if you need to respond to multiple gestures simultaneously
-(BOOL) Gesturerecognizer: (Uigesturerecognizer *) Gesturerecognizer Shouldrecognizesimultaneouslywithgesturerecognizer: (Uigesturerecognizer *) othergesturerecognizer{ return YES;}
Detailed gestures in iOS