UI手势

作者: 老七没问题 | 来源:发表于2019-04-09 17:21 被阅读0次

UIGestureRecongnizer:NSObject

1.-(void)addGestureRecognizer:

(UIGestureRecognizer *)gestureRecognizer 附加一个手势识别器到视图

点击tap

UITapGestureRecognizer: UIGestureRecognizer

1.创建一个UITapGestureRecognizer对象

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

2.numberOfTapsRequired 按几次触发

例:tap.numberOfTapsRequired = 2;

3.numberOfTouchesRequired 几根手指触发

例:tap.numberOfTouchesRequired = 2;

长按longpress

UILongPressGestureRecognizer:UIGestureRecognizer

1.创建一个UILongPressGestureRecognizer对象

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

2.minimumPressDuration判定长按需要的时间 默认为0.5s

例:longPress.minimumPressDuration = 1;

3.allowableMovement 允许长按过程中移动的像素 默认10

例:longPress.allowableMovement = 100;

4.常用绑定方法

if(longPress.state == UIGestureRecognizerStateBegan){

NSLog(@“长按”);

}

轻扫swipe

UISwipeGestureRecognizer:

UIGestureRecognizer

1.创建一个UISwipeGestureRecognizer对象

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

2.direction 滑动方向

例:swipe.direction = UISwipeGestureRecognizerDirectionLeft;

3.numberOfTouchesRequired 几根手指触发

旋转rotation

UIRotationGestureRecognizer:

UIGestureRecognizer

1.创建一个UIRotationGestureRecognizer对象

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

2.rotation 旋转速度

3.常用绑定方法

NSLog(@“旋转”);

UIView * view = rotation.view//获得当前手势所在的view

view.transform =

CGAffineTransformRotate(view.transform,rotation.rotation);//transform属性

rotation.rotation= 0;

拖拽 pan

UIPanGestureRecognizer : UIGestureRecognizer

1.创建一个UIPanGestureRecognizer对象

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

2.常用绑定方法

NSLog(@“拖拽”);

CGPoint translation = [pan translationInView: self.view];

UIView *view = pan.view;

view.center = CGPointMake(view.center.x + translation.x, view.center.y + translation.y);

[pan setTranslation:CGPointMake(0,0) inView:self.view];

捏合pinch

UIPinchGestureRecognizer:UIGestureRecognizer

1.创建一个UIPinchGestureRecognizer对象

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

2.常用绑定方法

UIView*view = pinch.view;

view.transform = CGAffineTransformScale(view.transform,pinch.scale,pinch.scale);

3.scale比例

例:pinch.scale =1;

屏幕边缘拖拽screenEdgePan

UIScreenEdgePanGestureRecognizer:UIPanGestureRecognizer

1.创建一个UIScreenEdgePanGestureRecognizer对象

UIScreenEdgePanGestureRecognizer * ScreenEdgePan = [[UIScreenEdgePanGestureRecognizer]initWithTarget:self action:@selector(screenEdgePan:)];

相关文章

  • UI总结-手势

    UI总结-手势 常用的6种手势: #import "ViewController.h" @...

  • UI手势

    手势识别器有:轻拍 长按 旋转 捏合 拖拽 清扫 屏幕边缘拖拽 在使用这些手势识别器时 先打开用户交互 image...

  • UI手势

    UIGestureRecongnizer:NSObject 1.-(void)addGestureRecogniz...

  • UI - 手势

    UIGestureRecognizer手势识别器 手势:有规律的触摸 UIGestureRecognizer抽象类...

  • UI手势

    手势:有规律的触摸 UIGestureRecognizer抽象类 七种手势:轻拍(tap)长按(longPress...

  • UI手势

    UIGestureRecognizer手势识别器 手势:有规律的触摸 UIGestureRecognizer抽象类...

  • 5.2 GestureRecognizer---UI手势

    GestureRecognizer---UI手势 基础控制器 导航栏视图控制器, 根试图控制器 单击手势 双击手势...

  • UI梳理——手势

    手势分类: 手势的创建: 方法的实现: 轻扫手势:UISwipeGestureRecognizer 长按手势: 以...

  • UI手势回顾

    UIGestureRecongnizer手势识别器 手势:有规律的触摸 UIGestureRecognizer抽象...

  • UI手势控件

    一、拖拽 示例代码: 复制代码 1 // 2 // YYViewController.m 3 // 06-拖拽事件...

网友评论

      本文标题:UI手势

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