There are six types of gesture recognition in iOS development:
Tap gestures (Tapgesturerecognizer),
Swipe gesture (Swipegesturerecognizer),
Long-press gesture (Longpressgesturerecognizer),
Drag gestures (Pangesturerecognizer),
Pinch gesture (Pinchgesturerecognizer),
Rotation gesture (Rotationgesturerecognizer),
1, tap gesture (Tapgesturerecognizer)
UITapGestureRecognizer *tapgesture = [[UITapGestureRecognizer alloc] initwithtarget:self action: @selector (tapgesture :)];tapgesture.numberoftapsrequired = 1; Number of clicks tapgesture.numberoftouchesrequired = 1; Click Hand Index [Self.view addgesturerecognizer:tapgesture];//tap Gesture Trigger Method-(void) Tapgesture: (UITapGestureRecognizer *) sender{ //your Code}
2, long press gesture (Longpressgesturerecognizer)
Uilongpressgesturerecognizer *longpressgesture = [[Uilongpressgesturerecognizer alloc] initwithtarget:self action:@ Selector (longpressgesture:)];//set long by time longpressgesture.minimumpressduration = 0.5; [Self.view addgesturerecognizer:longpressgesture];//Long Press gesture trigger Method-(void) Longpressgesture: (ID) sender{ Uilongpressgesturerecognizer *longpress = sender; if (longpress.state = = Uigesturerecognizerstatebegan) {//your Code}} Description: The general status of the long-press gesture starts as follows: Uigesturerecognizerstatebegan change: uigesturerecognizerstatechanged end: uigesturerecognizerstateended Cancel: UIGest urerecognizerstatecancelled failure: uigesturerecognizerstatefailed
3, swipe gesture (Swipegesturerecognizer)
Uiswipegesturerecognizer *swipegesture = [[Uiswipegesturerecognizer alloc] initwithtarget:self action: @selector ( Swipegesture:)];//set the direction of the swipe swipegesture.direction = uiswipegesturerecognizerdirectionright; Right [Self.view addgesturerecognizer:swipegesture]; Uiswipegesturerecognizer *swipegestureleft = [[Uiswipegesturerecognizer alloc] initwithtarget:self action: @selector ( Swipegesture:)];//set the direction of the swipe swipegestureleft.direction = Uiswipegesturerecognizerdirectionleft; Left [Self.view addgesturerecognizer:swipegestureleft];//swipe gesture trigger Method-(void) Swipegesture: (ID) sender{ Uiswipegesturerecognizer *swipe = sender;if (swipe.direction = = Uiswipegesturerecognizerdirectionleft) {//left swipe}if ( Swipe.direction = = uiswipegesturerecognizerdirectionright) {//Right Swipe}}
4, pinch gesture (pinchgesturerecognizer)
Uipinchgesturerecognizer *pinchgesture = [[Uipinchgesturerecognizer alloc] initwithtarget:self action: @selector ( Pinchgesture:)]; [Self.view addgesturerecognizer:pinchgesture];////Pinch gesture trigger Method-(void) Pinchgesture: (ID) sender{ Uipinchgesturerecognizer *gesture = sender;//gesture change if (gesture.state = = uigesturerecognizerstatechanged) {// Pinch gesture scale attribute record scaling _imageview.transform = Cgaffinetransformmakescale (Gesture.scale, Gesture.scale);} After end recovery if (gesture.state==uigesturerecognizerstateended) {[UIView animatewithduration:0.5 animations:^{_ Imageview.transform = cgaffinetransformidentity;//Cancel all deformation}];}}
5, drag gesture (Pangesturerecognizer)
Uipangesturerecognizer *pangesture = [[Uipangesturerecognizer alloc] initwithtarget:self action: @selector (pangesture :)]; [Self.view addgesturerecognizer:pangesture];//Drag Gesture Trigger Method-(void) Pangesture: (ID) sender{ uipangesturerecognizer * Pangesture = sender; Cgpoint movepoint = [Pangesture TranslationInView:self.view]; Your code}
6, rotation gesture (Rotationgesturerecognizer)
Uirotationgesturerecognizer *rotationgesture = [[Uirotationgesturerecognizer alloc] initwithtarget:self action:@ Selector (rotationgesture:)]; [Self.view addgesturerecognizer:rotationgesture];//Rotation gesture Trigger Method-(void) Rotationgesture: (ID) sender{ Uirotationgesturerecognizer *gesture = sender;if (gesture.state==uigesturerecognizerstatechanged) {_ Imageview.transform=cgaffinetransformmakerotation (gesture.rotation);} if (gesture.state==uigesturerecognizerstateended) {[UIView animatewithduration:1 animations:^{_imageview.transform =cgaffinetransformidentity;//cancel the deformation}];}}
Six types of gesture recognition in iOS development