标签:
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
标签:
原文地址:http://www.cnblogs.com/PJHome/p/5154251.html