My iOS Learning Path (iii): gesture recognizer

Source: Internet
Author: User

In iOS learning, the handling of gestures is extremely important, such as for images, we often need to rotate, zoom and move, and so on. Here is a summary, see the code.

1- (void) Viewdidload2 {3 [Super Viewdidload];4UIImage *image = [UIImage imagenamed:@"018.png"];5Uiimageview *imageview =[[Uiimageview alloc] initwithimage:image];6Imageview.frame = CGRectMake ( the, the, $, -);7 [Self.view Addsubview:imageview];8     9     //Turn on user interactionTenimageview.userinteractionenabled =YES; One     //Zoom gesture Recognizer AUipinchgesturerecognizer *pinges =[[Uipinchgesturerecognizer alloc] init]; -Pinges.Delegate=Self ; -      the [pinges addtarget:self Action: @selector (pinges:)]; - [ImageView addgesturerecognizer:pinges]; -      -     //Rotary gesture Recognizer +Uirotationgesturerecognizer *rotages =[[Uirotationgesturerecognizer alloc] init]; -Rotages.Delegate=Self ; +imageview.userinteractionenabled =YES; A [rotages addtarget:self Action: @selector (Rota:)]; at [ImageView addgesturerecognizer:rotages]; -      -      -     //Mobile gesture Recognizer -Uipangesturerecognizer *panges =[[Uipangesturerecognizer alloc] init]; - [panges addtarget:self Action: @selector (panges:)]; in [ImageView addgesturerecognizer:panges]; -      to     //long-press gesture recognizer +Uilongpressgesturerecognizer *longpress =[[Uilongpressgesturerecognizer alloc] init]; -      the     //set the long-time standard (default time is 0.5 seconds) *Longpress.minimumpressduration =1.0; $ [longpress addtarget:self Action: @selector (longpress:)];Panax Notoginseng [ImageView addgesturerecognizer:longpress]; -      the } +  A //The return value of this method indicates whether the gesture recognizer supports multi-gesture operations the-(BOOL) Gesturerecognizer: (Uigesturerecognizer *) Gesturerecognizer Shouldrecognizesimultaneouslywithgesturerecognizer: (Uigesturerecognizer *) Othergesturerecognizer + { -     returnYES; $ } $  - //long-Press operation -- (void) Longpress: (Uilongpressgesturerecognizer *) Ges the { -     //start a long, on-time OperationWuyi     if(Ges.state = =Uigesturerecognizerstatebegan) { theNSLog (@"begin"); -         //end a long, on-time Operation Wu}Else if(Ges.state = =uigesturerecognizerstateended) { -NSLog (@"End"); About     } $ } -  - //Move Operation -- (void) Panges: (Uipangesturerecognizer *) Ges A { +     //gets the distance that is moved relative to the parent view theCgpoint point =[Ges TranslationInView:self.view]; -     //Turn on animation $ [UIView Beginanimations:nil context:nil]; the     //Set Animation time the[UIView setanimationduration:1]; the     //moving through the deformation properties theGes.view.transform =cgaffinetransformtranslate (Ges.view.transform, Point.x, point.y); -     //since the gesture recognizer accumulates the distance of each move, the relative moving distance (0,0) needs to be set when moving once . in[Ges Settranslation:cgpointmake (0,0) InView:self.view]; the      the     //move through center point About //ges.view.center = cgpointmake (ges.view.center.x + point.x, ges.view.center.y + point.y); the //[Ges settranslation:cgpointmake (0, 0) InView:self.view]; the     //End of animation the [UIView commitanimations]; + } -  the //Rotation OperationBayi- (void) Rota: (Uirotationgesturerecognizer *) Ges the { the     //Set deformation properties -Ges.view.transform =cgaffinetransformrotate (Ges.view.transform, ges.rotation); -     //because the Cgaffinetransformrotate function will overlay each rotation angle, it is necessary to set the rotation angle of the gesture recognizer to 0; theGes.rotation =0; the } the  the //Scaling Operations -- (void) Pinges: (Uipinchgesturerecognizer *) Ges the { the //NSLog (@ "Get in ..."); the     //because the Cgaffinetransformscale function will multiply the scaling scale, you need to set the gesture Recognizer's zoom scale to 194Ges.view.transform =Cgaffinetransformscale (Ges.view.transform, Ges.scale, Ges.scale); theGes.scale =1.0f; the}

My iOS Learning Path (iii): gesture recognizer

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.