(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