The use of five big gestures

Source: Internet
Author: User

Tap (TAP), loogpress (Long Press), Rotation (rotate), Pinch (pinch), swipe (swipe), pan (drag)

If you do not respond to gestures, there are several reasons for this

1, see if added to the ImageView, if the userinteractionenabled is set to Yes

2. Check if background color is set, if not set, set background color

3, gesture conflict, then you need to set the priority of gestures, (intercept trigger events, gestures) set priority

* * The parent of the five major gesture inheritance: Uigesturerecognizer

UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initwithtarget:self Action: @selector (tapaction:)];

Set the number of tap fingers

tap.numberoftouchesrequired = 1;

Numberoftapsrequired set the number of finger clicks

tap.numberoftapsrequired = 1;

Addgesturerecognizer: Adding gestures

[Self.view Addgesturerecognizer:tap];

#pragma mark--------------Long Press--------------------------

Initialization

Uilongpressgesturerecognizer *longpress = [[Uilongpressgesturerecognizer alloc]initwithtarget:self Action: @selector (longpress:)];

Set the minimum duration pressed by default 0.5s

Longpress.minimumpressduration = 1;

longpress.numberoftouchesrequired = 2;

Addgesturerecognizer: Adding gestures to a view

[Self.view addgesturerecognizer:longpress];

#pragma mark---------dragged-----------------

Initialization

Uipangesturerecognizer *pan = [[Uipangesturerecognizer alloc]initwithtarget:self Action: @selector (pan:)];

Minimumnumberoftouches set the minimum number of fingers

Pan.minimumnumberoftouches = 2;

Maximumnumberoftouches

[Self.view Addgesturerecognizer:pan];

#pragma mark-------------Swipe------------------------

Initialization

Uiswipegesturerecognizer *swipe = [[Uiswipegesturerecognizer alloc]initwithtarget:self Action: @selector (swipe:)];

Direction setting the direction of the swipe

Swipe.direction = Uiswipegesturerecognizerdirectionleft;

The idea of dealing with gesture collisions: whose gestures are executed in a short time who executes the method first: Requiregesturerecognizertofail

You need a swipe gesture after you're done performing a drag gesture.

[Pan requiregesturerecognizertofail/* handles drag and swipe two gesture collision methods */:swipe/* first performed */];

[Self.view Addgesturerecognizer:swipe];

#pragma mark--------------kneading--------------------------

Uipinchgesturerecognizer *pinch = [[Uipinchgesturerecognizer alloc]initwithtarget:self Action: @selector (pinch:)];

[Self.view Addgesturerecognizer:pinch];

#pragma mark---------------Rotate-------------------------

Uirotationgesturerecognizer *rotation = [[Uirotationgesturerecognizer alloc]initwithtarget:self Action: @selector ( Rotation:)];

[Self.view addgesturerecognizer:rotation];

}

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

Make the image deform the same way by rotating gestures

Imageview.transform = Cgaffinetransformmakerotation (sender.rotation);

}

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

The transform should change its original form (which continues in this form if it is not restored) and is not related to gestures.

The proportion of changes that are obtained by gestures changes the shape of the ImageView.

Imageview.transform = Cgaffinetransformmakescale (Sender.scale, Sender.scale);

Imageview.transform = Cgaffinetransformscale (Imageview.transform, Sender.scale, Sender.scale);

Imageview.center = Self.view.center;

}

-(void) Swipe: (Uiswipegesturerecognizer *) sender{

Self.view.frame = CGRectMake (Cgrectgetwidth ([UIScreen mainscreen].bounds), 0, Cgrectgetwidth ([UIScreen mainscreen]. Bounds), Cgrectgetheight ([UIScreen mainscreen].bounds));

[UIView Animatewithduration:2 animations:^{

Self.view.frame = CGRectMake (0, 0, cgrectgetwidth ([UIScreen mainscreen].bounds), Cgrectgetheight ([UIScreen mainscreen ].bounds));

}];

NSLog (@ "Dsdb");

}

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

Locationinview: Get the touch point of the Click

Cgpoint Taploc = [Sender LocationInView:self.view];

NSLog (@ "%f%f", taploc.x,taploc.y);

Click on the location to set these points into the picture view

Imageview.center = Taploc;

}

-(void) Longpress: (Uilongpressgesturerecognizer *) sender{

Locationinview: Get the touch point of the Click

Cgpoint Taploc = [Sender LocationInView:self.view];

NSLog (@ "%f%f", taploc.x,taploc.y);

Animation

[UIView animatewithduration:0.2 animations:^{

Click on the location to set these points into the picture view

Imageview.center = Taploc;

}];

}

How to click Gestures

-(void) Tapaction: (UITapGestureRecognizer *) sender{

Get the view back to its original shape

Imageview.transform = cgaffinetransformidentity;

Self.view.backgroundColor = [Uicolor Redcolor];

Locationinview: Get the point of the click

Cgpoint Taploc = [Sender LocationInView:self.view];

NSLog (@ "%f%f", taploc.x,taploc.y);

Animation

[UIView animatewithduration:1 animations:^{

Click on the location to set these points into the picture view

Imageview.center = Taploc;

}];

}

The use of five big gestures

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.