常用的有以下几种
敲击
UITapGestureRecognizer
捏合(一般用于缩放)
UIPinchGestureRecognizer
拖拽
UIPanGestureRecognizer
轻扫
UISwipeGestureRecognizer
旋转
UIRotationGestureRecognizer
长按
UILongPressGestureRecognizer
- (void)addTap{
UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(tap:)];
tap.numberOfTapsRequired = 2;
[self.imageView addGestureRecognizer:tap];
UILongPressGestureRecognizer *longPress = [[UILongPressGestureRecognizer alloc]initWithTarget:self action:@selector(longpress:)];
[self.imageView addGestureRecognizer:longPress];
UISwipeGestureRecognizer *swipe = [[UISwipeGestureRecognizer alloc]initWithTarget:self action:@selector(swipe:)];
swipe.direction = UISwipeGestureRecognizerDirectionUp;
[self.imageView addGestureRecognizer:swipe];
UIRotationGestureRecognizer *rotation = [[UIRotationGestureRecognizer alloc]initWithTarget:self action:@selector(rotation:)];
[self.imageView addGestureRecognizer:rotation];
UIPinchGestureRecognizer *pinch = [[UIPinchGestureRecognizer alloc]initWithTarget:self action:@selector(pinch:)];
[self.imageView addGestureRecognizer:pinch];
UIPanGestureRecognizer *pan = [[UIPanGestureRecognizer alloc]initWithTarget:self action:@selector(pan:)];
[self.imageView addGestureRecognizer:pan];
}
- (void)tap:(UITapGestureRecognizer *)tap{
NSLog(@"%s",__func__);
}
- (void)longpress:(UILongPressGestureRecognizer *)longpress{
if(longpress.state == UIGestureRecognizerStateEnded){
NSLog(@"%s",__func__);
}
}
- (void)swipe:(UISwipeGestureRecognizer *)swipe{
NSLog(@"%s",__func__);
}
- (void)rotation:(UIRotationGestureRecognizer *)rotat{
NSLog(@"%s",__func__);
self.imageView.transform = CGAffineTransformRotate(self.imageView.transform,rotat.rotation);
rotat.rotation = 0;
}
- (void)pinch:(UIPinchGestureRecognizer *)pinch{
NSLog(@"%s",__func__);
self.imageView.transform = CGAffineTransformScale(self.imageView.transform, pinch.scale,pinch.scale);
pinch.scale = 1;
}
-(void)pan:(UIPanGestureRecognizer *)pan{
NSLog(@"%s",__func__);
CGPoint transP = [pan translationInView:self.imageView];
self.imageView.transform = CGAffineTransformTranslate(self.imageView.transform, transP.x, transP.y);
[pan setTranslation:CGPointZero inView:self.imageView];
}