Gesture actions (click Gesture, long press gesture, plan gesture)

Source: Internet
Author: User

1. Planning Gesture Manipulation

////VIEWCONTROLLER.M//1-28 Plotting gestures////Created by Ma C on 16/1/28.//copyright©2016 year BJSXT. All rights reserved.//#import "ViewController.h"@interfaceViewcontroller () @property (Strong, nonatomic) Uiswipegesturerecognizer*recognizer, @property (Strong, nonatomic) UIButton*btn;@end@implementationViewcontroller- (void) viewdidload {[Super viewdidload]; SELF.BTN= [[UIButton alloc] Initwithframe:cgrectmake (0,0, the,667)];    [Self.btn Setbackgroundcolor:[uicolor Redcolor];        [Self.view ADDSUBVIEW:SELF.BTN]; //a gesture can only correspond to one, the default is right, the left slide must be created in aSelf.recognizer=[[Uiswipegesturerecognizer alloc] initwithtarget:self action: @selector (Handleswipefrom)];        [Self.recognizer setdirection: (uiswipegesturerecognizerdirectionright)];            [Self.view AddGestureRecognizer:self.recognizer]; }- (void) handleswipefrom{//If you go to the right slide    if(self.recognizer.direction==uiswipegesturerecognizerdirectionright) {[UIView beginanimations:@"1"Context:nil]; [UIView setanimationduration:0.5];                [UIView Setanimationcurve:uiviewanimationcurveeaseinout];                [UIView Setanimationrepeatautoreverses:no]; Self.btn.frame= CGRectMake ( the,0, the,667);    [UIView commitanimations]; }    }
2. Click gestures and long-press gesture actions
#import "ViewController.h" @interface Viewcontroller () @property (strong,nonatomic) Uitextfield *field;@        End@implementation viewcontroller-(void) viewdidload {[Super viewdidload];    Gestures: swipe gesture, tap gesture, double click gesture, long press gesture, Self.field=[[uitextfield Alloc] Initwithframe:cgrectmake (80, 211, 114, 30)];        [email protected] "Please enter the content";            Note that the agent is not set [Self.view AddSubview:self.field]; Create a click Gesture UITapGestureRecognizer uitapgesturerecognizer *tap=[[uitapgesturerecognizer alloc] initwithtarget:self acti   On: @selector (wantdosomething)]; We created a gesture, but not the gesture on the specific control, that is to say: The gesture must rely on the control, when a specific control put a gesture, this gesture to respond//to the current view to add a click gesture,            (Place a Click gesture on the view) the following gesture correlation method is executed when the user clicks on the current view [Self.view Addgesturerecognizer:tap]; Create a long press gesture Uilongpressgesturerecognizer *longpress=[[uilongpressgesturerecognizer alloc] initwithtarget:self action:@    Selector (longpresswant)];              longpress.minimumpressduration=2.0;//minimum time is more than 2s [self.view addgesturerecognizer:longpress];          }//This method is called when the gesture is triggered.-(void) wantdosomething{NSLog (@ "click"); [Self.field Resignfirstresponder];} -(void) longpresswant{Uialertview *alert=[[uialertview alloc] initwithtitle:@ "trigger action" message:@ "long press gesture" Delegate:self can    celbuttontitle:@ "OK" otherbuttontitles:nil]; [Alert show];}


@end

Gesture actions (click Gesture, long press gesture, plan gesture)

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.