Uigesturerecognizer gesture Manipulation

Source: Internet
Author: User

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

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.