常见手势使用

常用的有以下几种

敲击
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);
    //复位,缩放比例为1
    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];

}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值