IOS UI05 _ gesture Reader
Gesture: Click, hold, rotate, pinch, drag, clean, clean
//// MainViewController. m // UI05 _ gesture reader /// Created by dllo on 15/8/4. // Copyright (c) 2015 zhozhicheng. all rights reserved. // # import MainViewController. h @ interface MainViewController () @ property (nonatomic, retain) UIImageView * imageView; @ property (nonatomic, retain) UIAlertView * alertView; @ end @ implementation MainViewController-(void) dealloc {[_ imageView release]; [_ alertView release]; [super dealloc]; }-(Void) viewDidLoad {[super viewDidLoad]; // Do any additional setup after loading the view. // UIImageView UIImage * image = [UIImage imageNamed: @footRight_03.jpg.jpg]; self. imageView = [[UIImageView alloc] initWithImage: image]; self. imageView. frame = CGRectMake (50,100,300,400); [self. view addSubview: self. imageView]; [_ imageView release]; // open the user interaction of the image, which is disabled by default. In addition, the control is label self. imageView. userInterac TionEnabled = YES; // use of gestures // 1. click UITapGestureRecognizer * tap = [[UITapGestureRecognizer alloc] initWithTarget: self action: @ selector (tapAction :)]; // set the number of clicks to trigger method tap. numberOfTapsRequired = 2; // set several fingers to click the tap. numberOfTouchesRequired = 2; // Add the gesture to the corresponding image [self. imageView addGestureRecognizer: tap]; [tap release]; // 2. long press UILongPressGestureRecognizer * longPress = [[UILongPressGestureRecognizer alloc] initWithTarg Et: self action: @ selector (longPressAction :)]; // sets the shortest time for longPress. minimumPressDuration = 2; // The distance to which the user's finger can be moved during a long press. allowableMovement = 200; // Add the gesture to the image [self. imageView addGestureRecognizer: longPress]; [longPress release]; // 3. rotate // create a rotation gesture UIRotationGestureRecognizer * rotation = [[UIRotationGestureRecognizer alloc] initWithTarget: self action: @ selector (rotationAction :)]; // place the gesture on the corresponding image [self. I MageView addGestureRecognizer: rotation]; // release [rotation release]; // 4. kneading // create UIPinchGestureRecognizer * pinch = [[UIPinchGestureRecognizer alloc] initWithTarget: self action: @ selector (pincheAction :)]; // Add it to the image [self. imageView addGestureRecognizer: pinch]; // release [pinch release]; // 5. drag UIPanGestureRecognizer * pan = [[UIPanGestureRecognizer alloc] initWithTarget: self action: @ selector (panAction :)]; [self. im AgeView addGestureRecognizer: pan]; [pan release]; // 6. cleaning UISwipeGestureRecognizer * swipe = [[UISwipeGestureRecognizer alloc] initWithTarget: self action: @ selector (swipeAction :)]; [self. imageView addGestureRecognizer: swipe]; [swipe release]; // direction of cleaning swipe. direction = uiswipegesturerecognizerdireup; // The gesture that appears after the screen boundary gesture iOS7.0 // UIScreenEdgePanGestureRecognizer} # pragma mark click method-(void) tapAction :( UITapGes TureRecognizer *) tap {NSLog (@ djkdajdo); self. imageView. image = [UIImage imageNamed: @angry_05.jpg];} # response method of pragma mark on time-(void) longPressAction :( UILongPressGestureRecognizer *) longPress {// long press status // longPress. state // A UIAlerView if (! Self. alertView) {self. alertView = [[UIAlertView alloc] initWithTitle: @ 404 message: @ error delegate: self cancelButtonTitle: @ confirm otherButtonTitles: nil, nil]; [self. alertView show]; [_ alertView release] ;}# pragma mark rotate the image using the image rotation gesture-(void) rotationAction :( UIRotationGestureRecognizer *) rotarion {// you can use a gesture to obtain the UIImageView * imageView = (UIImageView *) rotarion added by the gesture. view; // rotate the Image view by using the transform attribute of the view. transform = CGAffineTransformRotate (imageView. transform, rotarion. rotation); rotarion. rotation = 0 ;}# pragma mark scales the image by means of a pinch gesture-(void) pincheAction :( UIPinchGestureRecognizer *) pinche {// call the UIImageView * imageView = (UIImageView *) pinche. view; // use transform to change the image size. imageView. transform = CGAffineTransformScale (imageView. transform, pinche. scale, pinche. scale); pinche. scale = 1 ;}# pragma mark moves with the gesture by dragging the gesture-(void) panAction :( UIPanGestureRecognizer *) pan {UIImageView * imageView = (UIImageView *) pan. view; // obtain the uploaded point CGPoint p = [pan translationInView: imageView] through gestures; // set the Moving position imageView. transform = CGAffineTransformTranslate (imageView. transform, p. x, p. y); // to prevent the gesture from attempting to disappear during operation [pan setTranslation: CGPointZero inView: imageView];} # method for cleaning the pragma mark-(void) swipeAction :( UISwipeGestureRecognizer *) swipe {if (swipe. direction = direction) {NSLog (@) ;}}-(void) didReceiveMemoryWarning {[super didreceivemorywarning]; // Dispose of any resources that can be recreated .} /* # pragma mark-Navigation // In a storyboard-based application, you will often want to do a little preparation before navigation-(void) prepareForSegue :( UIStoryboardSegue *) segue sender :( id) sender {// Get the new view controller using [segue destinationViewController]. // Pass the selected object to the new view controller .} * // @ end