ios 手势加变形

@interface ViewController () <UIGestureRecognizerDelegate>
@property (weak, nonatomic) IBOutlet UIImageView *imageView;
@end

@implementation ViewController
//手势代理方法  返回YES是可以同时触发
-(BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer {
    return YES;
}

- (void)viewDidLoad {
    [super viewDidLoad];

    //拖拽
    UIPanGestureRecognizer *panGR = [[UIPanGestureRecognizer alloc]initWithTarget:self action:@selector(panGR:)];
    self.imageView.userInteractionEnabled = YES;
    [self.view addGestureRecognizer:panGR];

    //捏合
    UIPinchGestureRecognizer *pinchGR = [[UIPinchGestureRecognizer alloc]initWithTarget:self action:@selector(pinchGR:)];
    pinchGR.delegate = self;
    [self.view addGestureRecognizer:pinchGR];

    //旋转
    UIRotationGestureRecognizer *rotationGR = [[UIRotationGestureRecognizer alloc]initWithTarget:self action:@selector(rotationGR:)];
    rotationGR.delegate = self;
    [self.view addGestureRecognizer:rotationGR];

    //点击
    UITapGestureRecognizer *tapGR = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(tapGR:)];
    [self.view addGestureRecognizer:tapGR];
    
}

-(void)tapGR:(UITapGestureRecognizer*)gr {
    self.imageView.transform = CGAffineTransformIdentity;
}

-(void)rotationGR:(UIRotationGestureRecognizer*)gr {
    CGFloat rotation = gr.rotation;
    self.imageView.transform = CGAffineTransformRotate(self.imageView.transform, rotation);
    gr.rotation = 0;
}

-(void)pinchGR:(UIPinchGestureRecognizer*)gr {
    CGFloat scale = gr.scale;
    self.imageView.transform = CGAffineTransformScale(self.imageView.transform, scale, scale);
    gr.scale = 1;
}

-(void)panGR:(UIPanGestureRecognizer*)gr {
//    CGPoint translation = [gr translationInView:self.view];
//    CGPoint center = self.imageView.center;
//    center.x += translation.x;
//    center.y += translation.y;
//    self.imageView.center = center;
//    [gr setTranslation:CGPointZero inView:self.view];
    
    
    CGPoint translation = [gr translationInView:self.view];
    self.imageView.transform = CGAffineTransformTranslate(self.imageView.transform, translation.x, translation.y);
    [gr setTranslation:CGPointZero inView:self.view];
}
成功的三大原则: 1、坚持 2、不要脸 3、坚持不要脸
原文地址:https://www.cnblogs.com/xulinmei/p/7420209.html