美文网首页
UI手势识别器

UI手势识别器

作者: 青花_ | 来源:发表于2016-02-18 14:00 被阅读0次

七种手势:轻拍(tap)、长按(longPress)、旋转(rotation)、捏合(pinch)、拖拽(pan)、轻扫(swipe)、屏幕边缘拖拽(screenEdgePan)

功能描述:

附加到两个图片视图 UIImageView 的有拖动、捏合、旋转、点按;

而轻扫 附加在根视图 UIView 中。

拖动:进行当前图片视图位置移动

捏合:进行当前图片视图缩放

旋转:进行当前图片视图角度旋转

点按:双击恢复当前图片视图的缩放、角度旋转、不透明度

长按:设置当前图片视图的不透明度为0.7

轻扫:左右轻扫设置两个图片视图为居中,同时以垂直居中的特定偏移量定位

自定义手势:挠痒功能,左右扫动共3次或以上,设置两个图片视图为居中,同时以水平居中的特定偏移量定位

一、轻拍(tap)

 创建对象

获取到轻拍手势时 让self调用tapAction:方法

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

 添加手势

[imgView addGestureRecognizer:tap];

内存管理

[tap release];

点击次数

tap.numberOfTapsRequired = 2;

 手指个数

tap.numberOfTouchesRequired = 2;

二、长按(longPress)

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

[imgView addGestureRecognizer:longPress];

[longPress release];

设置长按时间

longPress.minimumPressDuration = 1;

三、旋转rotation

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

[imgView addGestureRecognizer:rotation];

[rotation release];

四、捏合pinch

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

[imgView addGestureRecognizer:pinch];

[pinch release];

五、拖拽pan

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

[imgView addGestureRecognizer:pan];

[pan release];

六、轻扫(swipe)

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

默认只识别向右

设置方向时 最多只能设置 水平(左/右)或者垂直(上/下)

swipe.direction = UISwipeGestureRecognizerDirectionRight | UISwipeGestureRecognizerDirectionLeft;

[imgView addGestureRecognizer:swipe];

[swipe release];

七、屏幕边缘拖拽screenEdgePan

UIScreenEdgePanGestureRecognizer *sep = [[UIScreenEdgePanGestureRecognizer alloc] initWithTarget:self action:@selector(sepAction:)];

需要设置拖拽的边缘

sep.edges = UIRectEdgeLeft;

[self.view addGestureRecognizer:sep];

[sep release];

相关文章

  • UI手势识别器

    - (void)viewDidLoad { [super viewDidLoad]; // Do any addi...

  • UI手势识别器

    七种手势:轻拍(tap)、长按(longPress)、旋转(rotation)、捏合(pinch)、拖拽(pan)...

  • UI手势识别器

    //七中手势:轻拍(tap) 长按(longPress) 旋转(rotation) 捏合(pinch) 拖拽(p...

  • 3.6 iOS手势识别的状态和手势识别器幕后原理

    2.2手势识别的状态和手势识别器幕后原理 (一)手势的状态 (二)离散型手势识别器和连续型手势识别器之间的对比: ...

  • Gesture手势

    手势识别器 手势识别器是对触摸事件做了封装,我们无需自己去判断某个手势是否触发,手势识别器本身起到了识别作用,我们...

  • 手势——UIGestureRecognizer

    一、简介 UIGestureRecognizer是具体手势识别器的基类。 手势识别器对象(或简单地说是手势识别器)...

  • UIGestureRecognizer

    什么是手势识别器? 手势识别器就是对触摸事件做了封装,我们不需要判断某个手势是否触发,手势识别器本身起到了识别作用...

  • 同时响应多个UIGestureRecognizer

    最近在做产品试戴,效果如下: 使用了多个手势识别器: UIRotationGestureRecognizer UI...

  • iOS手势识别

    UIGestureRecognizer手势识别器手势识别器是特殊的触摸事件UIGestureRecognizer是...

  • UIGestureRecognizer手势识别器学习笔记

    UIGestureRecognizer 具体手势识别器的基类。一个手势识别器对象,或者简单地说一个手势识别器,解耦...

网友评论

      本文标题:UI手势识别器

      本文链接:https://www.haomeiwen.com/subject/asvmkttx.html