UI--Gesture

别的不说 上干货
各种手势用法

1.轻拍
UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapAction)];
    self.imv.userInteractionEnabled = YES;//因为图片会阻断事件,所以在其上面添加手势的时候一定要打开交互
    [self.imv addGestureRecognizer:tap];
//    点击次数
    tap.numberOfTapsRequired = 2;
//    触控点个数
    tap.numberOfTouchesRequired = 2;
###################
- (void)tapAction{
    NSLog(@"AAAAAA");
}
//imv 是你要作用的对象
2.长按
    UILongPressGestureRecognizer *longPress = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(longPress:)];
    self.imv.userInteractionEnabled = YES;
    [self addGestureRecognizer:longPress];
#############
- (void)longPress:(UILongPressGestureRecognizer *)longPress{
    if (longPress.state == UIGestureRecognizerStateBegan) {
        NSLog(@"hehahah");
    }
}
    3.旋转
    UIRotationGestureRecognizer *rotate = [[UIRotationGestureRecognizer alloc] initWithTarget:self action:@selector(rotateAction:)];
    self.imv.userInteractionEnabled = YES;
    [self.imv addGestureRecognizer:rotate];
#######
- (void)rotateAction:(UIRotationGestureRecognizer *)rotateAction{
    self.imv.transform = CGAffineTransformRotate(self.imv.transform, rotateAction.rotation);
    [rotateAction setRotation:0];
}
注:transform 在这里是变换的意思
   4 捏合
    UIPinchGestureRecognizer *pinch = [[UIPinchGestureRecognizer alloc] initWithTarget:self action:@selector(pinchAction:)];
    self.imv.userInteractionEnabled = YES;
    [self.imv addGestureRecognizer:pinch];
########
- (void)pinchAction:(UIPinchGestureRecognizer *)pinchAction{
    self.imv.transform = CGAffineTransformScale(self.imv.transform, pinchAction.scale, pinchAction.scale);
    //1是倍数的意思----这是清空之前的状态
    pinchAction.scale = 1;
}
    5.平移
    UIPanGestureRecognizer *pan = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(panAction:)];
    self.imv.userInteractionEnabled = YES;
    [self.imv addGestureRecognizer:pan];
#########
- (void)panAction:(UIPanGestureRecognizer *)sender{
    NSLog(@"pan");

    //取到点的信息
    CGPoint point = [sender translationInView:self.imv];
    self.imv.transform = CGAffineTransformTranslate(self.imv.transform, point.x, point.y);

    //把每次保存的之前一次的移动距离清空
    [sender setTranslation:(CGPointZero) inView:self.imv];
每次平移都会先回到原点,然后再动
    self.imv.transform = CGAffineTransformMakeTranslation(point.x, point.y);
}
注:translation 是平移的意思
translateTransfrom 平移变换
   6. 清扫
    UISwipeGestureRecognizer *swipe = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(tapAction)];
    self.imv.userInteractionEnabled = YES;
    swipe.direction = UISwipeGestureRecognizerDirectionUp;
    [self addGestureRecognizer:swipe];
##########
   7. 边缘识别
    UIScreenEdgePanGestureRecognizer *edge = [[UIScreenEdgePanGestureRecognizer alloc]initWithTarget:edge action:@selector(tapAction)];
    self.imv.userInteractionEnabled = YES;
    [self addGestureRecognizer:edge];
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值