iOS 手势识别(拖动、旋转、捏合)
2017-08-17 17:08
423 查看
1.平移 UIPanGestureRecognizer *pan = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(pan:)]; 添加手势 [self.imageV addGestureRecognizer:pan]; 实现手势方法 手指在屏幕上移动进调用 - (void)pan:(UIPanGestureRecognizer *)pan{ 获取当前手指移动的偏移量 CGPoint transP = [pan translationInView:self.imageV]; NSLog(@"%@",NSStringFromCGPoint(transP)); Make它会清空上一次的形变. self.imageV.transform = CGAffineTransformMakeTranslation(transP.x, transP.y); self.imageV.transform = CGAffineTransformTranslate(self.imageV.transform,transP.x, transP.y); 复位,相对于上一次. [pan setTranslation:CGPointZero inView:self.imageV]; } 2.旋转 添加旋转手势 UIRotationGestureRecognizer *rotation = [[UIRotationGestureRecognizer alloc] initWithTarget:self action:@selector(rotation:)]; 设置代理,设置代理的目的就让它能够同时支持旋转跟缩放 rotation.delegate = self; 添加手势 [self.imageV addGestureRecognizer:rotation]; 当旋转时调用 - (void)rotation:(UIRotationGestureRecognizer *)rotation{ 旋转也是相对于上一次 self.imageV.transform = CGAffineTransformRotate(self.imageV.transform,rotation.rotation); 设置代理,设置代理的目的就让它能够同时支持旋转跟缩放 rotation.delegate = self; 也要做复位操作 rotation.rotation = 0; } 3.添加缩放手势 添加缩放手势 UIPinchGestureRecognizer *pinch = [[UIPinchGestureRecognizer alloc] initWithTarget:self action:@selector(pinch:)]; [self.imageV addGestureRecognizer:pinch]; 缩放手势时调用 -(void)pinch:(UIPinchGestureRecognizer *)pinch{ 平移也是相对于上一次 self.imageV.transform = CGAffineTransformScale(self.imageV.transform, pinch.scale, pinch.scale); 复位 pinch.scale = 1; }
相关文章推荐
- ios手势识别——旋转、捏合、滑动、拖动、长按
- iOS手势识别的详细使用(拖动,缩放,旋转,点击,手势依赖,自定义手势)
- iOS手势UIGestureRecognizer识别的详细使用(拖动,缩放,旋转,点击,手势依赖,自定义手势)
- iOS手势识别的详细使用(拖动,缩放,旋转,点击,手势依赖,自定义手势)
- iOS 手势操作:拖动、捏合、旋转、点按、长按、轻扫、自定义
- iOS手势识别的详细使用(拖动,缩放,旋转,点击,手势依赖,自定义手势)
- iOS手势识别的详细使用(拖动,缩放,旋转,点击,手势依赖,自定义手势)
- 【转】iOS手势识别的详细使用(拖动,缩放,旋转,点击,手势依赖,自定义手势) -- 不错不错
- iOS开发手势---拖动、捏合、旋转、点按、长按、轻扫
- iOS手势识别的详细使用(拖动,缩放,旋转,点击,手势依赖,自定义手势)
- iOS 手势操作:拖动、捏合、旋转、点按、长按、轻扫、自定义
- IOS Gesture手势(点击、捏合、滑动、长按、旋转、拖动)
- iOS手势识别的详细使用(拖动,缩放,旋转,点击,手势依赖,自定义手势)
- iOS学习笔记-068.手势识别02——捏合、拖拽、旋转手势
- iOS手势识别使用(拖动,缩放,旋转,点击,长按,滑动,自定义手势)等等
- iOS手势识别的详细使用(拖动,缩放,旋转,点击,手势依赖,自定义手势)
- iOS手势识别的详细使用(拖动,缩放,旋转,点击,手势依赖,自定义手势)
- iOS 手势操作:拖动、捏合、旋转、点按、长按、轻扫、自定义
- iOS手势识别的详细使用(拖动,缩放,旋转,点击,手势依赖,自定义手势)
- iOS手势识别的详细使用(拖动,缩放,旋转,点击,手势依赖,自定义手势)