Cat learn iOS (36) UI Gesture Event Rotation _ zoom _ drag

Source: Internet
Author: User

Cat Share, must boutique

Original articles, welcome reprint. Reprint Please specify: Sanayu's Blog
Address: http://blog.csdn.net/u013357243?viewmode=contents
Source: http://blog.csdn.net/u013357243/article/details/45560213

Effect

Complete a picture of pinch zoom, drag, and rotate the action.

Design Ideas Drag:

The first is the simplest drag

//Drag-(void) pantest{Uipangesturerecognizer *pan = [[Uipangesturerecognizer alloc] init]; [ Self. IconViewAddgesturerecognizer:pan]; [Pan AddTarget: SelfAction@selector(Panview:)];} - (void) Panview: (Uipangesturerecognizer *) pan{The value returned is the point at which the finger is pressed.    //1 2 3 4 5    CgpointPoint = [Pan Translationinview:pan. View];NSLog(@"Drag-and-drop event%@", Nsstringfromcgpoint (point));Cgpointtemp = Self. IconView. Center; Temp. x+ = Point. x; Temp. Y+ = Point. Y; Self. IconView. Center= temp;//If you can't understand it, just remember it OK .[Pan Settranslation:cgpointzero Inview:pan. View];}
Rotating:
- (void) rotationtest{//RotateUirotationgesturerecognizer *gesture = [[Uirotationgesturerecognizer alloc] init]; Gesture. Delegate= Self; [ Self. IconViewAddgesturerecognizer:gesture]; [Gesture AddTarget: SelfAction@selector(Rotationview:)];} - (void) Rotationview: (Uirotationgesturerecognizer *) gesture{//NSLog (@ "Spin event%.1f", gesture.rotation);    //Starting from the original position each time    //Self.iconView.transform = Cgaffinetransformmakerotation (gesture.rotation);    //increments a radian on the incoming transform basis     Self. IconView. Transform= Cgaffinetransformrotate ( Self. IconView. Transform, gesture. Rotation);//Rotate the arc 0 (note that the arc of rotation is not zeroed, but the arc of the current finger is rotated 0)Gesture. Rotation=0;//If you can't understand it, remember it's OK}
Kneading
-(void) pichtest{//pinch gesture uipinchgesturerecognizer *pinch = [[Uipinchgesturerecognizer alloc] init];Pinch. Delegate= Self;[Self. IconViewAddgesturerecognizer:pinch];[Pinch addtarget:self action: @selector (Pinchview:)];}-(void) Pinchview: (Uipinchgesturerecognizer *) pinch{//NSLog (@"Pinch event%.1f", pinch. scale);Self. IconView. Transform= Cgaffinetransformmakescale (pinch. scale, pinch. scale);//1.0*0.9Self. IconView. Transform= Cgaffinetransformscale (self. IconView. Transform, pinch. scale, pinch. scale);Pinch. scale=1.0;}
Simultaneous rotation and scaling

So that only one gesture can be used, and then in order to enable him to rotate and zoom simultaneously
Increase the agent so that multiple gestures can be judged.
To implement a proxy

    @interface NYViewController ()<UIGestureRecognizerDelegate>
// 该方法返回的BOOL值决定了view是否能够同时响应多个手势- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer{    NSLog(@"%@ - %@", gestureRecognizer.class, otherGestureRecognizer.class);    returnYES;}

Attention:

And then there's a place to watch.

Uiimageview to hook these two in order to be able to achieve interactive

Some of the middle of the algorithm is not much to say, the front of the blog has pictures of the picture, we are interested to see. Anyway, cats are generally used directly, or by virtue of the sense of guessing (this does not recommend that everyone learn ...) )

Cat learns iOS (36) UI Gesture Event Rotation _ zoom _ drag

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.