The Uigesturerecognizer class, used to detect and identify gestures used by the user when using the device, defines the basic behavior of all gestures. The following is the Uigesturerecognizer subclass, yo about handling specific user gesture behavior.
Click Gestures
*singletap=[[UITapGestureRecognizer alloc]initwithtarget:self Action: @selector (Singletap:)]; [Self.view Addgesturerecognizer:singletap]; // Click event -(void) Singletap: (UITapGestureRecognizer *) tapgestrue{ NSLog (@ " Click ");
Double-click Gestures
*doubletap=[[UITapGestureRecognizer alloc]initwithtarget:self Action: @selector (Doubletap:)]; doubletap.numberoftapsrequired=2; [Self.view Addgesturerecognizer:doubletap]; // Difference Click Double tap gesture [Singletap Requiregesturerecognizertofail:doubletap]; // Double click on Event -(void) Doubletap: (UITapGestureRecognizer *) taggestrue{ NSLog (@ " Double- click ");}
Swipe gestures
Uiswipegesturerecognizer *swipegesture=[[Uiswipegesturerecognizer alloc]initwithtarget:self Action: @selector ( Swipe:)]; // set swipe direction, default to right Swipegesture.direction=uiswipegesturerecognizerdirectiondown; [Self.view addgesturerecognizer:swipegesture]; // Swipe event -(void) Swipe: (Uiswipegesturerecognizer *) swipegesture{ NSLog (@ " Swipe gesture ");}
Translation
Uipangesturerecognizer *pangesture=[[Uipangesturerecognizer alloc]initwithtarget:self Action: @selector (pan:)] ; [Self.view addgesturerecognizer:pangesture]; // Pan Event -(void) Pan: (Uipangesturerecognizer *) pan{ cgpointpoint =[pan LocationInView:self.view]; NSLog (@ "%@", Nsstringfromcgpoint (point));}
Long-Press gestures
Uilongpressgesturerecognizer *longpressgesture=[[Uilongpressgesturerecognizer alloc]initwithtarget:self Action: @selector (longpress:)]; Longpressgesture.minimumpressduration=2; [Self.view addgesturerecognizer:longpressgesture];//long-press gesture event-(void) Longpress: (Uilongpressgesturerecognizer *) longpress{//Long Press to leave the call once, so you need to set the gesture State if(longpress.state==uigesturerecognizerstateended) { return; } NSLog (@"Long press for more than two seconds");}
Rotate gestures
Uirotationgesturerecognizer *rotation=[[Uirotationgesturerecognizer alloc]initwithtarget:self action:@ Selector (rotation:)]; [Self.view addgesturerecognizer:rotation]; // Rotation Event -(void) Rotation: (Uirotationgesturerecognizer *) rotation{ // Obtained angle float degree=rotation.rotation* (m_pi) According to the rotational radian; NSLog (@ "%f", Degree);}
Uigesturerecognizer gesture Manipulation