Six types of gesture recognition, what do you use?

Source: Internet
Author: User

//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?

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.