#import "ViewController.h"@interface ViewController (){
UIImageView *img;
}
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
img = [[UIImageView alloc]initWithFrame:self.view.frame];
img.image = [UIImage imageNamed:@"minion"];
[self.view addSubview:img];
img.userInteractionEnabled = YES;
#pragma mark 轻̥击̥
UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(qingji:)];
tap.numberOfTapsRequired = 1;
[img addGestureRecognizer:tap];
UITapGestureRecognizer *tap2 = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(qingjier:)];
tap2.numberOfTapsRequired = 2;
[img addGestureRecognizer:tap2];
//消除两个手势的影响;
[tap requireGestureRecognizerToFail:tap2];
//两个手指双击;
UITapGestureRecognizer *tap3 = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(qingjierer:)];
tap3.numberOfTapsRequired = 2;
tap3.numberOfTouchesRequired = 2;
[img addGestureRecognizer:tap3];
#pragma mark //轻̥扫̥
UISwipeGestureRecognizer *swipe = [[UISwipeGestureRecognizer alloc]initWithTarget:self action:@selector(qingsao:)];
[img addGestureRecognizer:swipe];
//设̥置̥轻̥扫̥的̥方̥向̥
swipe.direction = UISwipeGestureRecognizerDirectionUp;
#pragma mark 长̥按̥;
UILongPressGestureRecognizer *longPress = [[UILongPressGestureRecognizer alloc]initWithTarget:self action:@selector(changan:)];
[img addGestureRecognizer:longPress];
//最̥小̥长̥安̥时̥间̥
longPress.minimumPressDuration = 1;
#pragma mark 平̥移̥;
UIPanGestureRecognizer *pan = [[UIPanGestureRecognizer alloc]initWithTarget:self action:@selector(pingyi:)];
[img addGestureRecognizer:pan];
#pragma mark 捏合;
UIPinchGestureRecognizer *pinch = [[UIPinchGestureRecognizer alloc]initWithTarget:self action:@selector(niehe:)];
pinch.delegate = self;
[img addGestureRecognizer:pinch];
#pragma mark 旋̥转̥
UIRotationGestureRecognizer *rotation = [[UIRotationGestureRecognizer alloc]initWithTarget:self action:@selector(xuanzhuan:)];
rotation.delegate = self;
[img addGestureRecognizer:rotation];
}
/**
* 是否允许多个手势识别器同时有效
* Simultaneously : 同时地
*/
- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer
{
return YES;
}
-(void)xuanzhuan:(UIRotationGestureRecognizer *)rotation{
img.transform = CGAffineTransformRotate(img.transform, rotation.rotation);
rotation.rotation = 0;
}
-(void)niehe:(UIPinchGestureRecognizer *)pinch{
img.transform = CGAffineTransformScale(img.transform, pinch.scale, pinch.scale);
//捏̥合̥倍̥率̥
pinch.scale = 1;
NSLog(@"捏̥合̥");
}
-(void)qingji:(UITapGestureRecognizer *)tap{
NSLog(@"单̥机̥");
}
-(void)qingjier:(UITapGestureRecognizer *)tap{
NSLog(@"双̥机̥");
}
-(void)qingjierer:(UITapGestureRecognizer *)tap{
NSLog(@"两个手指双击");
}
-(void)qingsao:(UISwipeGestureRecognizer *)swipe{
NSLog(@"轻̥扫̥");
}
-(void)changan:(UILongPressGestureRecognizer *)longpress{
if (longpress.state == UIGestureRecognizerStateBegan) {
NSLog(@"长̥安̥");
return;
}
}
-(void)pingyi:(UIPanGestureRecognizer *)pan{
//在view上面挪动的距离 //translationInView表示相对于起点挪动的位置是最新2点之间的间距
CGPoint translation = [pan translationInView:pan.view];
CGPoint center = pan.view.center;
center.x += translation.x;
center.y += translation.y;
pan.view.center = center;
NSLog(@"平̥移̥");
// 清空移动的距离
[pan setTranslation:CGPointZero inView:pan.view];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
@end