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)