Use of gesture Recognizer 111

Source: Internet
Author: User

1. Use of Pat gesture recognizer

UITapGestureRecognizer *tapgesture=[[uitapgesturerecognizer alloc]initwithtarget:self Action: @selector ( Handletapgesture:)];

Set the number of taps to be tapped

tapgesture.numberoftapsrequired=1;

Set the number of touches you want to touch:

tapgesture.numberoftouchesrequired=2;//using Alt

Add gesture recognizer to the view being played

[Aview Addgesturerecognizer:tapgesture];

[Tapgesture release];

2. Create a translation gesture recognizer

Uipangesturerecognizer *pangesture=[[[uipangesturerecognizer alloc]initwithtarget:self Action: @selector ( Handlepangesture:)]autorelease];

[Aview Addgesturerecognizer:pangesture];

3. Create a rotary gesture recognizer

Uirotationgesturerecognizer *rotationgesture=[[uirotationgesturerecognizer alloc]initwithtarget:self action:@ Selector (handlerotationgesture:)];

[Aview Addgesturerecognizer:rotationgesture];

4. Create a zoom gesture recognizer

Uipinchgesturerecognizer *pinchgesture=[[uipinchgesturerecognizer alloc]initwithtarget:self Action: @selector ( Handlepinchgesture:)];

[Aview addgesturerecognizer:pinchgesture];//kneading

tapgesture.delegate=self;

rotationgesture.delegate=self;

pinchgesture.delegate=self;

5. Create a long-press gesture recognizer

Uilongpressgesturerecognizer *longpressgesture=[[[uilongpressgesturerecognizer alloc]initWithTarget:self action:@ Selector (handlelongpressgesture:)]autorelease];

[Aview Addgesturerecognizer:longpressgesture];

longpressgesture.minimumpressduration=0.5;

6. Create a swipe gesture recognizer

Uiswipegesturerecognizer *swipegesture=[[[uiswipegesturerecognizer alloc]initwithtarget:self Action: @selector ( Handleswipegesture:)]autorelease];

[Aview Addgesturerecognizer:swipegesture];

Swipegesture.direction=uiswipegesturerecognizerdirectiondown;

7. Create a screen edge swipe recognizer

Uiscreenedgepangesturerecognizer *screenedgegesture=[[[uiscreenedgepangesturerecognizer Alloc]initWithTarget: Self action: @selector (handlescreenedgegesture:)]autorelease];

[Self.view Addgesturerecognizer:screenedgegesture];

Screenedgegesture.edges=uirectedgeleft;

When a gesture recognizer object is recognized, the proxy object is queried, and the other gesture recognizers are allowed to be recognized at the same time. If this protocol method returns Yes, it means allow. Not allowed by default

-(BOOL) Gesturerecognizer: (Uigesturerecognizer *) Gesturerecognizer Shouldrecognizesimultaneouslywithgesturerecognizer: (Uigesturerecognizer *) othergesturerecognizer{

return YES;

}

-(void) Handlepangesture: (Uipangesturerecognizer *) sender{

UIView *aview=sender.view;

Gets the displacement increment that the gesture produces in the view's corresponding coordinate system

Cgpoint Point=[sender TranslationInView:aView.superview];

Create new deformations based on the last view of the graph

Aview.transform=cgaffinetransformtranslate (Aview.transform, Point.x, POINT.Y);

Zeroing the currently generated increment

[Sender Settranslation:cgpointzero InView:aView.superview];

}

-(void) Handlerotationgesture: (Uirotationgesturerecognizer *) sender{

UIView *aview=sender.view;

Aview.transform=cgaffinetransformrotate (Aview.transform, sender.rotation);

sender.rotation=0;//set the angle increment of rotation to 0;

}

-(void) Handlepinchgesture: (Uipinchgesturerecognizer *) sender{

UIView *aview=sender.view;

Aview.transform=cgaffinetransformscale (Aview.transform, Sender.scale, Sender.scale);

sender.scale=1;

}

Use of gesture Recognizer 111

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.