//1, tap gesture (Tapgesturerecognizer)//New tap gestureUITapGestureRecognizer *tapgesture =[[UITapGestureRecognizer alloc] initwithtarget:self action: @selector (tapgesture:)];//set number of clicks and click -to-hand indextapgesture.numberoftapsrequired =1;//Click Counttapgesture.numberoftouchesrequired =1;//Click Hand Index[Self.view addgesturerecognizer:tapgesture];//tap Gesture Trigger method-(void) Tapgesture: (ID) sender{//What to do after a light click}
//2, Long press gesture (Longpressgesturerecognizer)//add a long push gestureUilongpressgesturerecognizer *longpressgesture =[[Uilongpressgesturerecognizer alloc] initwithtarget:self action: @selector (longpressgesture:)];//set long by TimeLongpressgesture.minimumpressduration =0.5;//(2 seconds)[Self.view addgesturerecognizer:longpressgesture];//frequent gesture triggering method-(void) Longpressgesture: (ID) sender{Uilongpressgesturerecognizer*longpress =Sender; if(Longpress.state = =Uigesturerecognizerstatebegan) {Uialertview*alter = [[Uialertview alloc] Initwithtitle:@"Tips"Message@"Long Press Trigger" Delegate: Nil Cancelbuttontitle:@"Cancel"Otherbuttontitles:nil]; [Alter show]; }}
//3, swipe gesture (Swipegesturerecognizer)//add a swipe gestureUiswipegesturerecognizer *swipegesture =[[Uiswipegesturerecognizer alloc] initwithtarget:self action: @selector (swipegesture:)];//set the direction of the swipeSwipegesture.direction = Uiswipegesturerecognizerdirectionright;//Default Right[Self.view addgesturerecognizer:swipegesture];//add a swipe gestureUiswipegesturerecognizer *swipegestureleft =[[Uiswipegesturerecognizer alloc] initwithtarget:self action: @selector (swipegesture:)];//set the direction of the swipeSwipegestureleft.direction = Uiswipegesturerecognizerdirectionleft;//Default Right[Self.view Addgesturerecognizer:swipegestureleft];//Swipe gesture Trigger method-(void) Swipegesture: (ID) sender{Uiswipegesturerecognizer*swipe =Sender; if(Swipe.direction = =uiswipegesturerecognizerdirectionleft) { //Swipe left to do things } if(Swipe.direction = =uiswipegesturerecognizerdirectionright) { //Swipe right to do things }}
//4, pinch gesture (pinchgesturerecognizer)//Add a pinch gestureUipinchgesturerecognizer *pinchgesture =[[Uipinchgesturerecognizer alloc] initwithtarget:self action: @selector (pinchgesture:)];[ Self.view Addgesturerecognizer:pinchgesture];////Pinch gesture triggering method-(void) Pinchgesture: (ID) sender{Uipinchgesturerecognizer*gesture =Sender; //when gestures change if(Gesture.state = =uigesturerecognizerstatechanged) { //scaling of the scale property record in a pinch gesture_imageview.transform =Cgaffinetransformmakescale (Gesture.scale, Gesture.scale); } //Recover after end if(gesture.state==uigesturerecognizerstateended) {[UIView animatewithduration:0.5animations:^{_imageview.transform= Cgaffinetransformidentity;//Cancel all deformation }]; }}
// 5, drag gesture (Pangesturerecognizer) // Add a drag gesture Uipangesturerecognizer *pangesture = [[Uipangesturerecognizer alloc] initwithtarget:self action: @selector ( Pangesture:)]; [Self.view addgesturerecognizer:pangesture]; // drag gesture -(void) Pangesture: (ID) sender{ *pangesture = sender; = [Pangesture translationInView:self.view]; // do what you want to do }
//6, rotation gesture (Rotationgesturerecognizer)//Add a rotation gestureUirotationgesturerecognizer *rotationgesture =[[Uirotationgesturerecognizer alloc] initwithtarget:self action: @selector (rotationgesture:)];[ Self.view Addgesturerecognizer:rotationgesture];//Rotate gestures-(void) Rotationgesture: (ID) sender{Uirotationgesturerecognizer*gesture =Sender; if(gesture.state==uigesturerecognizerstatechanged) {_imageview.transform=cgaffinetransformmakerotation (gesture.rotation); } if(gesture.state==uigesturerecognizerstateended) {[UIView animatewithduration:1animations:^{_imageview.transform=cgaffinetransformidentity;//Cancel the deformation }]; } }
Six types of gesture recognition, what do you use?