//
// ViewController.m
#import "ViewController.h"
@interface ViewController ()
@property (weak, nonatomic) IBOutlet UIImageView *imageView;
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
// 给imageView添加手势
self.imageView.userInteractionEnabled = YES;
// 创建『旋转』手势
UIRotationGestureRecognizer *rotation = [[UIRotationGestureRecognizer alloc] initWithTarget:self action:@selector(rotation:)];
[self.imageView addGestureRecognizer:rotation];
}
- (void)rotation:(UIRotationGestureRecognizer *)recognizer
{
// 获取手势旋转的角度
NSLog(@"%f",recognizer.rotation);
// self.imageView.transform = CGAffineTransformMakeRotation(recognizer.rotation);
// 默认传递的旋转的角度都是相对于最开始的位置
// 我们这里更改
self.imageView.transform = CGAffineTransformRotate(self.imageView.transform, recognizer.rotation);
recognizer.rotation = 0; //清零
}
@end
手势识别器(UIGestureRecognizer)- UIRotationGestureRecognizer(旋转)
最新推荐文章于 2024-05-17 14:20:31 发布