iOS 手势识别(拖动、旋转、捏合)

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;
        }
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值