IOS Common gestures

Source: Internet
Author: User

Uigesturerecognizer has encapsulated the various gestures of iOS, fully satisfying the user's need for gestures.

The following is a detailed application and description of various gestures, hope to be helpful to everyone. ^_^

- (void) viewdidload {[Super viewdidload]; //Do any additional setup after loading the view.Self.view.backgroundColor =[Uicolor Grouptableviewbackgroundcolor]; _imageview= [[Uiimageview alloc]initwithframe:cgrectmake (self.view.frame.size.width- Max)/2, (self.view.frame.size.height- Max)/2, Max, Max)]; _imageview.userinteractionenabled= YES;//interactive enable, allow interface interaction_imageview.image = [UIImage imagenamed:@"Cat.png"];        [Self.view Addsubview:_imageview]; //Click the TaprecognizerUITapGestureRecognizer *Singletap; Singletap=[[UITapGestureRecognizer alloc] initwithtarget:self action: @selector (Singletap:)]; Singletap.numberoftapsrequired=1;//number of clicks =1 Click[_imageview Addgesturerecognizer:singletap];//add a gesture monitor to the object;//Double-click the TaprecognizerUITapGestureRecognizer *doubletap =[[UITapGestureRecognizer alloc] initwithtarget:self action: @selector (Doubletap:)]; Doubletap.numberoftapsrequired=2;//number of clicks = 2 Double-click[_imageview Addgesturerecognizer:doubletap];//add a gesture monitor to the object;        /*1. Double-click the gesture to determine if the monitoring fails to trigger the action of the click Gesture, or the first click on the double-click responds to clicking Event 2. Causes a click to be determined if a double-click is clicked, and the call is delayed.     is a normal phenomenon. */[Singletap Requiregesturerecognizertofail:doubletap]; //Pinch zoom gesture PinchUipinchgesturerecognizer *pinch; Pinch=[[Uipinchgesturerecognizer alloc]initwithtarget:self Action: @selector (handlepinch:)]; //[_imageview addgesturerecognizer:pinch];//when added to _imageview, it is to put your finger in the _imageview operation[Self.view Addgesturerecognizer:pinch];//when Self is self, the entire view can be _imageview (action in response to events) .Pinch.Delegate=Self ; //rotation gesture RotationUirotationgesturerecognizer *rotaterecognizer =[[Uirotationgesturerecognizer alloc] Initwithtarget:self    Action: @selector (handlerotate:)]; [Self.view Addgesturerecognizer:rotaterecognizer];//when Self is self, the entire view can be _imageview (action in response to events) .Rotaterecognizer.Delegate=Self ; //Swipe gesture SwiperecognizerUiswipegesturerecognizer *swiperecognizer =[[Uiswipegesturerecognizer alloc] Initwithtarget:self    Action: @selector (handleswipe:)]; [Self.view Addgesturerecognizer:swiperecognizer];//when Self is self, the entire view can be _imageview (action in response to events) .Swiperecognizer.direction = Uiswipegesturerecognizerdirectionleft;//action is left slideSwiperecognizer.Delegate=Self ; //drag gesture PanrecognizerUipangesturerecognizer *panrecognizer =[[Uipangesturerecognizer alloc] Initwithtarget:self    Action: @selector (Handlepan:)]; [_imageview Addgesturerecognizer:panrecognizer];//Key statement, add a gesture monitor;Panrecognizer.maximumnumberoftouches =1; Panrecognizer.Delegate=Self ; //long-Press gesture LongpressrecognizerUilongpressgesturerecognizer *longpressrecognizer =[[Uilongpressgesturerecognizer alloc] Initwithtarget:self    Action: @selector (handlelongpress:)];    [_imageview Addgesturerecognizer:longpressrecognizer]; Longpressrecognizer.minimumpressduration=1.0f;//Trigger long-press event time: 1 secondsLongpressrecognizer.Delegate=Self ; }-(void) Singletap: (uitapgesturerecognizer*) recognizer{//Handling Click ActionsNSLog (@"Click action");}-(void) Doubletap: (uitapgesturerecognizer*) recognizer{//handling Double-click OperationsNSLog (@"Double-click action");}- (void) Handlepinch: (uipinchgesturerecognizer*) recognizer{NSLog (@"Scaling Operations");//Handling Scaling Operations//Zoom to ImageView_imageview.transform =Cgaffinetransformscale (_imageview.transform, Recognizer.scale, Recognizer.scale); //Zoom to Self.view because recognizer is added to the Self.view//recognizer.view.transform = Cgaffinetransformscale (Recognizer.view.transform, Recognizer.scale, Recognizer.scale);Recognizer.scale =1;}- (void) Handlerotate: (uirotationgesturerecognizer*) recognizer{NSLog (@"Rotation Operation");//Handling Rotation Operations//rotation to ImageView_imageview.transform =cgaffinetransformrotate (_imageview.transform, recognizer.rotation); //rotate to Self.view, because recognizer is added to the Self.view//recognizer.view.transform = cgaffinetransformrotate (Recognizer.view.transform, recognizer.rotation);Recognizer.rotation =0;}- (void) Handleswipe: (uiswipegesturerecognizer*) recognizer{//Handling Slide Operations    if(recognizer.direction==uiswipegesturerecognizerdirectionleft) {NSLog (@"Slide Left slide operation"); }Else if(recognizer.direction==uiswipegesturerecognizerdirectionright) {NSLog (@"Slide Right Slide operation"); }}-(void) Handlepan: (uipangesturerecognizer*) recognizer{NSLog (@"Drag Action"); //To handle the drag operation, the drag is based on the ImageView, and if it is rotated, the drag direction is also relative to imageview up and down, rather than the screen pair up or downCgpoint translation =[recognizer Translationinview:_imageview]; Recognizer.view.center= Cgpointmake (recognizer.view.center.x +translation.x, Recognizer.view.center.y+TRANSLATION.Y); [Recognizer Settranslation:cgpointzero Inview:_imageview];}-(void) Handlelongpress: (uilongpressgesturerecognizer*) recognizer{//handles a long press operation, the start end is called, so a long press 1 will execute 2 times    if(Recognizer.state = =Uigesturerecognizerstatebegan) {NSLog (@"start Long Press operation"); }Else if(Recognizer.state = =uigesturerecognizerstateended) {NSLog (@"End Long Press operation"); }}- (void) didreceivememorywarning {[Super didreceivememorywarning]; //Dispose of any resources the can be recreated.}

IOS Common gestures

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.