//支持手勢(shì)同時(shí)觸發(fā)的代理方法
-(BOOL)gestureRecognizer:(UIGestureRecognizer*)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer*)otherGestureRecognizer {
returnYES;
}
- (void)viewDidLoad {
[superviewDidLoad];
UIPanGestureRecognizer*pan = [[UIPanGestureRecognizeralloc]initWithTarget:selfaction:@selector(pan:)];
UIPinchGestureRecognizer*pinch = [[UIPinchGestureRecognizeralloc]initWithTarget:selfaction:@selector(pinch:)];
pinch.delegate=self;
UIRotationGestureRecognizer*rotation = [[UIRotationGestureRecognizeralloc]initWithTarget:selfaction:@selector(rotation:)];
rotation.delegate=self;
UITapGestureRecognizer*tap = [[UITapGestureRecognizeralloc]initWithTarget:selfaction:@selector(tap:)];
tap.numberOfTapsRequired=2;
[self.viewaddGestureRecognizer:pan];
[self.viewaddGestureRecognizer:pinch];
[self.viewaddGestureRecognizer:rotation];
[self.viewaddGestureRecognizer:tap];
}
-(void)pan:(UIPanGestureRecognizer*)sender {
CGPointpanPoint = [sendertranslationInView:self.view];
self.imageView.transform=CGAffineTransformTranslate(self.imageView.transform, panPoint.x, panPoint.y);
//每次用完把translation中累加的值清空
[sendersetTranslation:CGPointZeroinView:self.view];
}
-(void)pinch:(UIPinchGestureRecognizer*)sender {
self.imageView.transform=CGAffineTransformScale(self.imageView.transform, sender.scale, sender.scale);
sender.scale=1;
}
-(void)rotation:(UIRotationGestureRecognizer*)sender {
self.imageView.transform=CGAffineTransformRotate(self.imageView.transform, sender.rotation);
sender.rotation=0;
}
-(void)tap:(UITapGestureRecognizer*)sender {
self.imageView.transform=CGAffineTransformIdentity;
}