#pragma-------- 1.点击
UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(tapAction:)]; // 初始化
tap.numberOfTouchesRequired = 1;// 默认值是1 设置点击手指的个数
tap.numberOfTapsRequired =1; // 设置点击的次数
[self.view addGestureRecognizer:tap]; // 添加到view视图
-(void)tapAction:(UITapGestureRecognizer *)sender // 单击手势的方法
{
// self.view.backgroundColor = [UIColor redColor];
imageView.transform = CGAffineTransformIdentity;//恢复视图的初始状态
CGPoint tapLoc = [sender locationInView:self.view];
NSLog(@"%f %f",tapLoc.x,tapLoc.y);
// 点击的位置 设置图片视图的中心点
[UIView animateWithDuration:0.5 animations:^{
imageView.center = tapLoc;
}]; //写动画
}
#pragma--------2长按
UILongPressGestureRecognizer *longPress = [[UILongPressGestureRecognizer alloc]initWithTarget:self action:@selector(longPress:)];
longPress.minimumPressDuration = 2;//设置长按最小时间
[self.view addGestureRecognizer:longPress]; // 把手势添加到view视图上
-(void)longPress:(UILongPressGestureRecognizer *)sender
{
self.view.backgroundColor = [UIColor grayColor];
CGPoint tapLoc = [sender locationInView:self.view];
NSLog(@"%f %f",tapLoc.x,tapLoc.y);
// 点击的位置 设置图片视图的中心点
[UIView animateWithDuration:2 animations:^{
imageView.center = tapLoc;
}]; //写动画
}
#pragma--------3.拖拽
UIPanGestureRecognizer *pan = [[UIPanGestureRecognizer alloc]initWithTarget:self action:@selector(Pan:)];
pan.minimumNumberOfTouches = 2; // 设置最小的手指个数
pan.maximumNumberOfTouches = 2; // 设置最大的手指个数
[self.view addGestureRecognizer:pan];
- (void)Pan:( UIPanGestureRecognizer *)sender
{
self.view.backgroundColor = [UIColor whiteColor];
CGPoint tapLoc = [sender locationInView:self.view];
NSLog(@"%f %f",tapLoc.x,tapLoc.y);
imageView.center = tapLoc;
}
#pragma--------4.轻扫
UISwipeGestureRecognizer *swipe = [[UISwipeGestureRecognizer alloc]initWithTarget:self action:@selector(Swipe:)];
swipe.direction = UISwipeGestureRecognizerDirectionLeft;//设置轻扫的方向
[self.view addGestureRecognizer:swipe];//添加到view视图上
- (void)Swipe:(UISwipeGestureRecognizer *)sender
{
self.view.backgroundColor = [UIColor orangeColor];
self.view.frame =CGRectMake(CGRectGetWidth([UIScreen mainScreen].bounds), 0,CGRectGetWidth([UIScreen mainScreen].bounds), CGRectGetHeight([UIScreen mainScreen].bounds));
[UIView animateWithDuration:2 animations:^{
self.view.frame = CGRectMake(0, 0, CGRectGetWidth([UIScreen mainScreen].bounds) ,CGRectGetHeight([UIScreen mainScreen].bounds));
}];
}
#pragma--------5.捏合
UIPinchGestureRecognizer *pinch = [[UIPinchGestureRecognizer alloc]initWithTarget:self action:@selector(pinch:)];
[self.view addGestureRecognizer:pinch];
- (void)pinch:(UIPinchGestureRecognizer *)sender
{
// 通过手势得到变化比例 让imageView形态发生改变
imageView.transform = CGAffineTransformScale(imageView.transform, sender.scale, sender.scale) ;
imageView.center = self.view.center;
}
#pragma--------6.旋转
UIRotationGestureRecognizer *rotion = [[UIRotationGestureRecognizer alloc]initWithTarget:self action:@selector( Rotion:)];
[self.view addGestureRecognizer:rotion];
// Do any additional setup after loading the view, typically from a nib.
-(void)Rotion:( UIRotationGestureRecognizer *)sender
{
imageView.transform = CGAffineTransformMakeRotation(sender.rotation);//通过旋转手势让图片进行相同的变形
}