UIGestureRecognizer抽象类,六大手势是其子类;

  • UITapGestureRecognizer        点击
  • UIPinchGestureRecognizer         缩放
  • UIRotationGestureRecognizer     旋转
  • UISwipeGestureRecognizer         轻扫
  • UIPanGestureRecognizer             拖动
  • UILongPressGestureRecognizer   长按

typedef NS_ENUM(NSInteger, UIGestureRecognizerState) {//手势当前的状态

UIGestureRecognizerStatePossible, (默认)

UIGestureRecognizerStateBegan,      (开始)

UIGestureRecognizerStateChanged,(已经改变)

UIGestureRecognizerStateEnded,  (结束)

UIGestureRecognizerStateCancelled, (取消)

UIGestureRecognizerStateFailed,  (失败)

UIGestureRecognizerStateRecognized = UIGestureRecognizerStateEnded

}

一、拖动手势  UIPanGestureRecognizer

  UIPanGestureRecognizer *panGesture =[[UIPanGestureRecognize alloc]  initWithTarget:self action:@selection(handlePan:)];

  [view  addGestureRecognizer:panGesture];

- (void)handlePan:(UIPanGestureRecognizer *)panGesture{
CGPoint translation = [panGesture translationInView:self.view];
CGPoint point = CGPointMake(panGesture.view.center.x + translation.x,panGesture.view.center.y + translation.y);
panGesture.view.center = point;
[panGesture setTranslation:CGPointZero inView:self.view];
}
  

1、确保view是可交互的 view.userInteractionEnabled = yes;

2、translationInView (相对点击点的偏移量) locationInView(相对屏幕实时坐标);

3、setTranslation:CGPointZero inView(每次初始化位置) 和translationInView同时使用;

4、velocityInView (获取速度矢量)  

二、捏合手势 UIPinchGestureRecognizer

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

  [view addGestureRecognizer:pinchGesture];

- (void)handlePinch:(UIPinchGestureRecognizer *)recognizer{
CGFloat scale = recognizer.scale;
recognizer.view.transform = CGAffineTransformMakeScale(scale, scale);// 每次缩放都回复原来基础下变化
// recognizer.view.transform = CGAffineTransformScale(recognizer.view.transform, scale, scale);//在已经缩放大小基础下累加变化
// recognizer.scale = 1.0;
}

  scale 缩放倍数 ,velocity 缩放速率;

三、旋转手势 UIRotationGestureRecognizer

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

  [view addGestureRecognizer:rotationGesture];

- (void)handleRotation:(UIRotationGestureRecognizer *)recognizer {
recognizer.view.transform = CGAffineTransformRotate(recognizer.view.transform, recognizer.rotation);
recognizer.rotation = 0.0;
}

四、点击手势 UITapGestureRecognizer

@property (nonatomic) NSUInteger  numberOfTapsRequired;       // 点击次数(默认一次)
@property (nonatomic) NSUInteger numberOfTouchesRequired __TVOS_PROHIBITED; // 需要手字数(默认一个点击点)

五、长按手势 UILongPressGestureRecognizer

@property (nonatomic) NSUInteger numberOfTapsRequired;      // Default is 0. The number of full taps required before the press for gesture to be recognized
@property (nonatomic) NSUInteger numberOfTouchesRequired __TVOS_PROHIBITED; // Default is 1. Number of fingers that must be held down for the gesture to be recognized @property (nonatomic) CFTimeInterval minimumPressDuration; // Default is 0.5. 最小长按时间
@property (nonatomic) CGFloat allowableMovement; // Default is 10. 长按时允许移动的距离

六、轻扫手势 UISwipeGestureRecognizer

typedef NS_OPTIONS(NSUInteger, UISwipeGestureRecognizerDirection) {
UISwipeGestureRecognizerDirectionRight = << ,
UISwipeGestureRecognizerDirectionLeft = << ,
UISwipeGestureRecognizerDirectionUp = << ,
UISwipeGestureRecognizerDirectionDown = <<
};
@property(nonatomic) UISwipeGestureRecognizerDirection direction; //轻扫方向

号外:同时响应多种手势

设置手势delegate实现方法

- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer{
return YES;
}





手势UIGestureRecognizer的更多相关文章

  1. 点击事件touches与ios的手势UIGestureRecognizer

    .h文件 @property (weak,nonatomic) IBOutlet UILabel *messageLabel;@property (weak,nonatomic) IBOutlet U ...

  2. [BS-25] IOS中手势UIGestureRecognizer概述

    IOS中手势UIGestureRecognizer概述 一.概述 iPhone中处理触摸屏的操作,在3.2之前是主要使用的是由UIResponder而来的如下4种方式: - (void)touches ...

  3. iOS手势UIGestureRecognizer的使用失效问题

    问题:视图正常展示在界面中,父层是放在window上的,底部的一个控件的点击事件失效(所有设置都正常) 解决思路:虽然视图能够正常展示,但是发现父类视图的底部尺寸比子类的视图的尺寸小,也就是说上层视图 ...

  4. IOS手势UIGestureRecognizer

    UIGestureRecognizer是一个抽象类,定义了所有手势的基本行为,它有6个子类处理具体的手势: 1.UITapGestureRecognizer (任意手指任意次数的点击) // 点击次数 ...

  5. 使用iOS手势UIGestureRecognizer

    UIKit中包含了UIGestureRecognizer类,用于检测发生在设备中的手势.UIGestureRecognizer是一个抽象类,定义了所有手势的基本行为,它有下面一些子类用于处理具体的手势 ...

  6. 屏蔽手势UIGestureRecognizer 先后响应

    在iOS5一下对于手势的识别能力并不强,比如iOS6上面按钮的一个tap事件,最先接收的是uiview,并相应,而不是最上面的button,这时候就需要判断手势所在的位置和手势所在的控制器了 如下例子 ...

  7. iOS手势UIGestureRecognizer的使用及手势冲突的解决办法【转】

    转自:iOS开发中的手势体系——UIGestureRecognizer分析及其子类的使用 关于手势的一篇很好的帖子,转载过来免得丢失.你可能最感兴趣的是手势间的互斥处理,那么就搜索 4.手势间的互斥处 ...

  8. IOS中手势UIGestureRecognizer

    通常在对视图进行缩放移动等操作的时候我们可以用UIScrollView,因为它里边自带了这些功能,我们要做的就是告诉UIScrollView的几个相关参数就可以了 但是没有实现旋转的手势即UIRota ...

  9. 关于iOS的手势UIGestureRecognizer问题

    typedef NS_ENUM(NSInteger, UIGestureRecognizerState) { UIGestureRecognizerStatePossible, // 尚未识别是何种手 ...

随机推荐

  1. json对象数组的创建、遍历、添加、删除、修改、js的splice()用法

    本文链接:https://blog.csdn.net/houfengfei668/article/details/79843625 )第二种方式:手动构造json对象数组 )for )用splice方 ...

  2. linux下使用自带mail发送邮件

    linux下使用自带mail发送邮件 mailx工具说明: linux可以通过安装mailx工具,mailx是一个小型的邮件发送程序,一般可以通过该程序在linux系统上,进行监控linux系统状态并 ...

  3. eclipse新建maven项目和聚合项目

    1.new maven project :  next 2.勾选 create a simple project  :  next 3.Group Id:项目的包路径 如com.jiayou.zjl, ...

  4. .net中的泛型全面解析

    从2.0起我们一直就在谈论泛型,那么什么是泛型,泛型有什么好处,与泛型相关的概念又该怎么使用,比如泛型方法,泛型委托.这一篇我会全面的介绍泛型. 那么首先我们必须搞清楚什么是泛型,泛型其实也是一种类型 ...

  5. nginx代理配置备份

    补充: 代理对文件大小的限制, server {client_max_body_size 100M;listen 9096;server_name gate.chaohuoyy.com; locati ...

  6. 搜索框下面显示提示数据(数据是ajax读取)

    1.前台页面 <div style="margin: 0 auto"> <input type="text" id="wenxian ...

  7. Algo: Basic

    1. 二维数组的查找 2. 替换空格 3. 从尾到头打印链表 4. 重建二叉树 5. 用两个栈实现队列 6. 旋转数组的最小数字 7. 斐波那契数列 8. 跳台阶 9. 变态跳台阶 10. 矩阵覆盖 ...

  8. @Value的使用

    <Spring源码解析>笔记 使用@Value赋值:1.基本数值2.可以写SpEL: #{}3.可以写${}:取出配置文件[properties]中的值(在运行环境变量里面的值) 1.创建 ...

  9. ctrl+shift+k取消

    因为typora软件和搜狗输入法软件的快捷键重合了,ctrl+shift+k在typora中是代码块的快捷键,而在搜狗输入法中是软键盘快捷键,显然软键盘不重要. 搜狗输入法的ctrl+shift+k取 ...

  10. thingkphp 路由实例

    我们已经了解了如何定义路由规则,下面我们来举个例子加深印象. 假设我们定义了News控制器如下(代码实现仅供参考): namespace Home\Controller; use Think\Cont ...