手势识别器

一.轻拍手势 (tap)

1.定义一个触发方法

UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action :@selector(tapAction:)];

2.设置

(1)响应事件的轻拍次数

tap.numberOfTapsRequired = 2;   (两次)


(2)需要几根手指

tap.numberOfTouchedRequired = 2;




二.长按手势(longPress)

1.定义一个触发方法

UILongPressGestureRecognizer *longPress = [[UILongPressGestureRecognizer alloc]initWithTarget:self action:@selector(longPressAction:)];


2.设置

(1)触发方法是所需要的时间

longPress.minimumPressDuration = 3;   //3秒


(2)长按时 允许用户移动手指的距离

longPress.allowableMovement = 100;



三.轻扫手势(swipe)

1.定义一个触发方法

UISwipeGestureRecognizer *swipe = [[UISwipeGestureRecognizer alloc]initWithTarget:self action:@selector(swipeAction:)];



2.设置

轻扫方向

swipe.direction = UISwipeGestureRecognizerDirectionLeft  |  UISwipeGestureRecognizerDirectionRight;


四.拖拽手势(pan)

1.定义一个触发方法

UIPanGestureRecognizer *pan = [[UIPanGestureRecognizer alloc]initWithTarget:self action:@selector(panAction:)];


2.拖拽的触发方法设置

- (void)panAction : (UIPanGestureRecognizer *)pan

{

    NSLog(@"拖拽");

    

    //通过手势的view属性 获取到当前手势添加到的view

    UIImageView *imageView = (UIImageView *)pan.view;

    

    //获取到 当前手指接触的点

    CGPoint p = [pan translationInView:imageView];

    

    //让view变形

    imageView.transform = CGAffineTransformTranslate(imageView.transform, p.x, p.y);

    

    //重置手势的属性

    [pan setTranslation:CGPointZero inView:imageView];

    

}



五.旋转手势(rotation)

1,定义触发方法

UIRotationGestureRecognizer *rotation = [[UIRotationGestureRecognizer alloc]initWithTarget:self action:@selector(rotationAction:)];


2.触发方法设置

(1)获取到当前手势添加到得 view

    UIImageView *imageView = (UIImageView *)rotation.view;

    

(2)让view旋转 利用旋转手势的 旋转弧度

    imageView.transform = CGAffineTransformRotate(imageView.transform, rotation.rotation);

    rotation.rotation = 0;





六.捏合手势(pinch)

1.定义触发方法

UIPinchGestureRecognizer *pinch = [[UIPinchGestureRecognizer alloc]initWithTarget:self action:@selector(pinchAction:)];

2.触发方法设置

(1)获取当前的view

    UIImageView *imageView = (UIImageView *)pinch.view;

    

(2)在x,y轴方向 放大 缩小

    imageView.transform = CGAffineTransformScale(imageView.transform, pinch.scale, 1);

    pinch.scale = 1;




七.屏幕边缘拖拽

1.定义触发方法

IScreenEdgePanGestureRecognizer *screenEdgePan = [[UIScreenEdgePanGestureRecognizer alloc]initWithTarget:self action:@selector(screenPan:)];


2.设置

(1)设置检测哪一边的屏幕边缘

screenEdgePan.edges = UIRectEdgeLeft;


(2)将UIImageView的用户交互打开,使它能响应轻拍

[imageView setUserInteractionEnabled:YES];






  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值