美文网首页iOS学习笔记
IOS 手势 的用法

IOS 手势 的用法

作者: JakieZhang | 来源:发表于2016-12-22 08:54 被阅读23次

//支持手势同时触发的代理方法

-(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;

}

相关文章

网友评论

    本文标题:IOS 手势 的用法

    本文链接:https://www.haomeiwen.com/subject/rwucvttx.html