iOS basic gestures

Source: Internet
Author: User

#import "TouchViewController.h"@interfaceTouchviewcontroller ()@end@implementationTouchviewcontroller- (ID) Initwithnibname: (NSString *) Nibnameornil Bundle: (NSBundle *) nibbundleornil{ Self=[Super Initwithnibname:nibnameornil Bundle:nibbundleornil]; if(self) {//Custom Initialization    }    returnSelf ;}- (void) viewdidload{[Super Viewdidload]; //Do any additional setup after loading the view.Self.view.backgroundColor =[Uicolor Graycolor]; Nsarray*imagearr = [Nsarray arraywithobjects:@"Cyansquare",@"Magentasquare",@"Yellowsquare", nil];  for(inti =0; I <3; i + +) {Uiimageview*imageview = [[Uiimageview alloc] Initwithframe:cgrectmake (Ten+ -*i, -+ the*i, -, -)];; Imageview.image=[UIImage Imagenamed:imagearr[i]]; Imageview.userinteractionenabled=YES;                [Self.view Addsubview:imageview]; //Add a tap gesture[self addgesture:imageview];    [ImageView release]; }        }//Add gesture Recognizer- (void) Addgesture: (Uiimageview *) imageview{//1. Add Click event, click Gesture RecognizerUITapGestureRecognizer *tap =[[UITapGestureRecognizer alloc] initwithtarget:self action: @selector (Tapclick:)]; //set the action of the Clicktap.numberoftapsrequired =2; //add a gesture to a view[ImageView Addgesturerecognizer:tap];    [Tap release]; //    //2. Create a mobile gesture//Uipangesturerecognizer *pan = [[Uipangesturerecognizer alloc] initwithtarget:self action: @selector (move:)];//[ImageView Addgesturerecognizer:pan];//[Pan release]; //3, zoom, pinch gestureUipinchgesturerecognizer *pin =[[Uipinchgesturerecognizer alloc] initwithtarget:self action: @selector (Pinclick:)];    [ImageView Addgesturerecognizer:pin];        [Pin release]; //4. RotationUirotationgesturerecognizer *rota =[[Uirotationgesturerecognizer alloc] initwithtarget:self action: @selector (Rota:)];    [ImageView Addgesturerecognizer:rota];    [Rota release]; //5. Long PressUilongpressgesturerecognizer *longpress =[[Uilongpressgesturerecognizer alloc] initwithtarget:self action: @selector (longpress:)];    [ImageView addgesturerecognizer:longpress];        [Longpress release]; //6-1, swipe gesture, a gesture can only support a gesture, in order to support multiple, you have to re-create multiple directions//will clash with moving gestures.Uiswipegesturerecognizer *swip1 =[[Uiswipegesturerecognizer alloc] initwithtarget:self action: @selector (SWIP:)]; Swip1.direction=Uiswipegesturerecognizerdirectionup;    [ImageView ADDGESTURERECOGNIZER:SWIP1];    [Swip1 release]; //6-2. Swipe gestureUiswipegesturerecognizer *SWIP2 =[[Uiswipegesturerecognizer alloc] initwithtarget:self action: @selector (SWIP:)]; Swip2.direction=Uiswipegesturerecognizerdirectiondown;    [ImageView ADDGESTURERECOGNIZER:SWIP2];    [SWIP2 release]; //6-3. Swipe gestureUiswipegesturerecognizer *SWIP3 =[[Uiswipegesturerecognizer alloc] initwithtarget:self action: @selector (SWIP:)]; Swip3.direction=Uiswipegesturerecognizerdirectionleft;    [ImageView ADDGESTURERECOGNIZER:SWIP3];    [SWIP3 release]; //6-4. Swipe gestureUiswipegesturerecognizer *SWIP4 =[[Uiswipegesturerecognizer alloc] initwithtarget:self action: @selector (SWIP:)]; Swip4.direction=Uiswipegesturerecognizerdirectionright;    [ImageView ADDGESTURERECOGNIZER:SWIP4]; [SWIP4 release];}//events that implement gestures are triggered only when you click on a picture- (void) Tapclick: (UITapGestureRecognizer *) sender{[Self.view BringSubviewToFront:sender.view];}//implement mobile gestures, similar to Touchmove- (void) Move: (Uipangesturerecognizer *) sender{//a fixed notationCgpoint point =[Sender TranslationInView:self.view]; Sender.view.center= Cgpointmake (sender.view.center.x + point.x, Sender.view.center.y +point.y); [Sender Settranslation:cgpointzero InView:self.view];}//the ability to implement pinch gestures- (void) Pinclick: (Uipinchgesturerecognizer *) sender{Sender.view.transform=Cgaffinetransformscale (Sender.view.transform, Sender.scale, Sender.scale); Sender.scale=1; }//Implement rotation- (void) Rota: (Uirotationgesturerecognizer *) sender{Sender.view.transform=cgaffinetransformrotate (Sender.view.transform, sender.rotation); Sender.rotation=1;}

iOS basic gestures

Related Article

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.