(Material source code) modemios IOS () UI gesture event rotation _ zooming _ Drag, iosui

Source: Internet
Author: User

(Material source code) modemios IOS () UI gesture event rotation _ zooming _ Drag, iosui

CAT/CAT sharing, must be excellent

For Original Articles, please reprint them. Reprinted Please note: Yan Nai-yu's blog
Http://blog.csdn.net/u013357243? Viewmode = contents
Source code: http://download.csdn.net/detail/u013357243/8671943

Effect

Click, drag, and rotate an image.

Code: NYViewController. m
/// NYViewController. m // rotate _ zoom _ Drag // Created by apple on 15-5-7. // Copyright (c) 2015 znycat. all rights reserved. // # import "NYViewController. h "# import" NYViewController. h "@ interface NYViewController () <strong> @ property (weak, nonatomic) IBOutlet UIImageView * iconView; @ end @ implementation NYViewController-(void) viewDidLoad {[super viewDidLoad]; // kneading [self pichTest]; // rotating [self rotationTest]; // drag [self panTest];} // drag-(void) panTest {UIPanGestureRecognizer * pan = [[UIPanGestureRecognizer alloc] init]; [self. iconView addGestureRecognizer: pan]; [pan addTarget: self action: @ selector (panView :)];}-(void) panView :( UIPanGestureRecognizer *) pan {// The returned value is the point at which the finger is pressed as the origin // 1 2 3 4 5 CGPoint = [pan translationInView: pan. view]; NSLog (@ "drag event % @", NSStringFromCGPoint (point); CGPoint temp = self. iconView. center; temp. x + = point. x; temp. y + = point. y; self. iconView. center = temp; // if you cannot understand it, remember OK [pan setTranslation: CGPointZero inView: pan. view];} // The BOOL value returned by this method determines whether the view can respond to multiple gestures simultaneously-(BOOL) gestureRecognizer :( UIGestureRecognizer *) gestureRecognizer author :( UIGestureRecognizer *) otherGestureRecognizer {NSLog (@ "% @-% @", gestureRecognizer. class, otherGestureRecognizer. class); return YES;}-(void) pichTest {// kneading gesture UIPinchGestureRecognizer * pinch = [[UIPinchGestureRecognizer alloc] init]; pinch. delegate = self; [self. iconView addGestureRecognizer: 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.9 self. iconView. transform = CGAffineTransformScale (self. iconView. transform, pinch. scale, pinch. scale); pinch. scale = 1.0;}-(void) rotationTest {// rotate UIRotationGestureRecognizer * gesture = [[UIRotationGestureRecognizer alloc] init]; gesture. delegate = self; [self. iconView addGestureRecognizer: gesture]; [gesture addTarget: self action: @ selector (rotationView :)];}-(void) rotationView :( UIRotationGestureRecognizer *) gesture {// NSLog (@ "rotation event %. 1f ", gesture. rotation); // each time starting from the initial position // self. iconView. transform = CGAffineTransformMakeRotation (gesture. rotation); // increments the input transform to a radian self. iconView. transform = CGAffineTransformRotate (self. iconView. transform, gesture. rotation); // clears the rotating radians (note that the radians of the image are not cleared, but the radians of the current finger are cleared) gesture. rotation = 0; // if you cannot understand it, remember it.} @ end

Related Article

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.