码迷,mamicode.com
首页 > 移动开发 > 详细

ios开发--旋转、移动、缩放手势实例代码

时间:2014-07-16 21:03:23      阅读:248      评论:0      收藏:0      [点我收藏+]

标签:os   art   for   io   cti   代码   

  1. // 添加所有的手势  
  2. - (void) addGestureRecognizerToView:(UIView *)view  
  3. {  
  4.     // 旋转手势  
  5.     UIRotationGestureRecognizer *rotationGestureRecognizer = [[UIRotationGestureRecognizer alloc] initWithTarget:self action:@selector(rotateView:)];  
  6.     [view addGestureRecognizer:rotationGestureRecognizer];  
  7.       
  8.     // 缩放手势  
  9.     UIPinchGestureRecognizer *pinchGestureRecognizer = [[UIPinchGestureRecognizer alloc] initWithTarget:self action:@selector(pinchView:)];  
  10.     [view addGestureRecognizer:pinchGestureRecognizer];  
  11.       
  12.     // 移动手势  
  13.     UIPanGestureRecognizer *panGestureRecognizer = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(panView:)];  
  14.     [view addGestureRecognizer:panGestureRecognizer];  
  15. }  
  16.   
  17. // 处理旋转手势  
  18. - (void) rotateView:(UIRotationGestureRecognizer *)rotationGestureRecognizer  
  19. {  
  20.     UIView *view = rotationGestureRecognizer.view;  
  21.     if (rotationGestureRecognizer.state == UIGestureRecognizerStateBegan || rotationGestureRecognizer.state == UIGestureRecognizerStateChanged) {  
  22.         view.transform = CGAffineTransformRotate(view.transform, rotationGestureRecognizer.rotation);  
  23.         [rotationGestureRecognizer setRotation:0];  
  24.     }  
  25. }  
  26.   
  27. // 处理缩放手势  
  28. - (void) pinchView:(UIPinchGestureRecognizer *)pinchGestureRecognizer  
  29. {  
  30.     UIView *view = pinchGestureRecognizer.view;  
  31.     if (pinchGestureRecognizer.state == UIGestureRecognizerStateBegan || pinchGestureRecognizer.state == UIGestureRecognizerStateChanged) {  
  32.         view.transform = CGAffineTransformScale(view.transform, pinchGestureRecognizer.scale, pinchGestureRecognizer.scale);  
  33.         pinchGestureRecognizer.scale = 1;  
  34.     }  
  35. }  
  36.   
  37. // 处理拖拉手势  
  38. - (void) panView:(UIPanGestureRecognizer *)panGestureRecognizer  
  39. {  
  40.     UIView *view = panGestureRecognizer.view;  
  41.     if (panGestureRecognizer.state == UIGestureRecognizerStateBegan || panGestureRecognizer.state == UIGestureRecognizerStateChanged) {  
  42.         CGPoint translation = [panGestureRecognizer translationInView:view.superview];  
  43.         [view setCenter:(CGPoint){view.center.x + translation.x, view.center.y + translation.y}];  
  44.         [panGestureRecognizer setTranslation:CGPointZero inView:view.superview];  
  45.     }  
  46. }  

ios开发--旋转、移动、缩放手势实例代码,布布扣,bubuko.com

ios开发--旋转、移动、缩放手势实例代码

标签:os   art   for   io   cti   代码   

原文地址:http://www.cnblogs.com/swallow37/p/3836362.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!