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

ios手势识别之旋转+缩放

时间:2016-01-23 22:59:22      阅读:249      评论:0      收藏:0      [点我收藏+]

标签:

 1 #import "NJViewController.h"
 2 
 3 @interface NJViewController ()<UIGestureRecognizerDelegate>
 4 @property (weak, nonatomic) IBOutlet UIImageView *iconView;
 5 
 6 @end
 7 
 8 @implementation NJViewController
 9 
10 - (void)viewDidLoad
11 {
12     [super viewDidLoad];
13     
14     [self pichTest];
15     [self rotationTest];
16 }
17 
18 // 该方法返回的BOOL值决定了view是否能够同时响应多个手势
19 - (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer
20 {
21     NSLog(@"%@ - %@", gestureRecognizer.class, otherGestureRecognizer.class);
22     return YES;
23 }
24 
25 - (void)pichTest
26 {
27     // 捏合手势
28     UIPinchGestureRecognizer *pinch = [[UIPinchGestureRecognizer alloc] init];
29     pinch.delegate = self;
30     
31     [self.iconView addGestureRecognizer:pinch];
32     [pinch addTarget:self action:@selector(pinchView:)];
33 }
34 
35 
36 - (void)pinchView:(UIPinchGestureRecognizer *)pinch
37 {
38 //    self.iconView.transform = CGAffineTransformMakeScale(pinch.scale, pinch.scale);
39     self.iconView.transform = CGAffineTransformScale(self.iconView.transform, pinch.scale, pinch.scale);
40     
41     pinch.scale = 1.0;
42 }
43 
44 - (void)rotationTest
45 {
46     // 旋转
47     UIRotationGestureRecognizer *gesture = [[UIRotationGestureRecognizer alloc] init];
48     gesture.delegate = self;
49     
50     [self.iconView addGestureRecognizer:gesture];
51     [gesture addTarget:self action:@selector(rotationView:)];
52 }
53 
54 - (void)rotationView:(UIRotationGestureRecognizer *)gesture
55 {
56 //    每次从最初的位置开始
57 //    self.iconView.transform = CGAffineTransformMakeRotation(gesture.rotation);
58 //    在传入的transform基础上递增一个弧度
59     self.iconView.transform = CGAffineTransformRotate(self.iconView.transform, gesture.rotation);
60     // 将旋转的弧度清零(注意不是将图片旋转的弧度清零, 而是将当前手指旋转的弧度清零)
61     gesture.rotation = 0;// 如果理解不了 , 记住就OK
62 }
63 
64 @end

 

ios手势识别之旋转+缩放

标签:

原文地址:http://www.cnblogs.com/PJHome/p/5154251.html

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