iOS手势UIGestureRecognizer

UIGestureRecognizer是一个抽象类,定义了所有手势的基本行为,它有6个子类处理具体的手势:

1.UITapGestureRecognizer (任意手指任意次数的点击)

// 点击次数

numberOfTapsRequired

// 手指个数

numberOfTouchesRequired

[plain] view plaincopy

  1. UITapGestureRecognizer *tapGestureRecognizer = [[UITapGestureRecognizer alloc] init];
  2. [tapGestureRecognizer addTarget:self action:@selector(gestureRecognizerHandle:)];
  3. [tapGestureRecognizer setNumberOfTapsRequired:2];
  4. [tapGestureRecognizer setNumberOfTouchesRequired:2];
  5. [self.view addGestureRecognizer:tapGestureRecognizer];
  6. [tapGestureRecognizer release];

 

2.UIPinchGestureRecognizer (两个手指捏合动作)

// 手指捏合,大于1表示两个手指之间的距离变大,小于1表示两个手指之间的距离变小

scale

// 手指捏合动作时的速率(加速度)

velocity

[plain] view plaincopy

  1. UIPinchGestureRecognizer *pinchGestureRecognizer = [[UIPinchGestureRecognizer alloc] init];
  2. [pinchGestureRecognizer addTarget:self action:@selector(gestureRecognizerHandle:)];
  3. [self.view addGestureRecognizer:pinchGestureRecognizer];
  4. [pinchGestureRecognizer release];

3.UIPanGestureRecognizer (摇动或者拖拽)

// 最少手指个数

minimumNumberOfTouches

// 最多手指个数

maximumNumberOfTouches

[plain] view plaincopy

  1. UIPanGestureRecognizer *panGestureRecognizer = [[UIPanGestureRecognizer alloc] init];
  2. [panGestureRecognizer addTarget:self action:@selector(gestureRecognizerHandle:)];
  3. [panGestureRecognizer setMinimumNumberOfTouches:1];
  4. [panGestureRecognizer setMaximumNumberOfTouches:5];
  5. [self.view addGestureRecognizer:panGestureRecognizer];
  6. [panGestureRecognizer release];

4.UISwipeGestureRecognizer (手指在屏幕上滑动操作手势)

// 滑动手指的个数

numberOfTouchesRequired

// 手指滑动的方向 (Up,Down,Left,Right)

direction

[plain] view plaincopy

  1. UISwipeGestureRecognizer *swipeGestureRecognizer = [[UISwipeGestureRecognizer alloc] init];
  2. [swipeGestureRecognizer addTarget:self action:@selector(gestureRecognizerHandle:)];
  3. [swipeGestureRecognizer setNumberOfTouchesRequired:2];
  4. [swipeGestureRecognizer setDirection:UISwipeGestureRecognizerDirectionRight];
  5. [self.view addGestureRecognizer:swipeGestureRecognizer];
  6. [swipeGestureRecognizer release];

5.UIRotationGestureRecognizer (手指在屏幕上旋转操作)

// 旋转方向,小于0为逆时针旋转手势,大于0为顺时针手势

rotation

// 旋转速率

velocity

[plain] view plaincopy

  1. UIRotationGestureRecognizer *rotationGestureRecognizer = [[UIRotationGestureRecognizer alloc] init];
  2. [rotationGestureRecognizer addTarget:self action:@selector(gestureRecognizerHandle:)];
  3. [self.view addGestureRecognizer:rotationGestureRecognizer];
  4. [rotationGestureRecognizer release];

6.UILongPressGestureRecognizer (长按手势)

// Default is 0. The number of full taps required before the press for gesture to be recognized

numberOfTapsRequired

// 需要长按的手指的个数

numberOfTouchesRequired

// 需要长按的时间,最小为0.5s

minimumPressDuration

// 手指按住允许移动的距离

allowableMovement

[plain] view plaincopy

    1. UILongPressGestureRecognizer *longPressGestureRecognizer = [[UILongPressGestureRecognizer alloc] init];
    2. [longPressGestureRecognizer addTarget:self action:@selector(gestureRecognizerHandle:)];
    3. [longPressGestureRecognizer setMinimumPressDuration:1.0f];
    4. [longPressGestureRecognizer setAllowableMovement:50.0];
    5. [self.view addGestureRecognizer:longPressGestureRecognizer];
    6. [longPressGestureRecognizer release];

iOS手势UIGestureRecognizer,布布扣,bubuko.com

时间: 2024-10-17 18:32:20

iOS手势UIGestureRecognizer的相关文章

iOS手势UIGestureRecognizer识别的详细使用(拖动,缩放,旋转,点击,手势依赖,自定义手势) (转)

1.UIGestureRecognizer介绍 手势识别在iOS上非常重要,手势操作移动设备的重要特征,极大的增加了移动设备使用便捷性. iOS系统在3.2以后,为方便开发这使用一些常用的手势,提供了UIGestureRecognizer类.手势识别UIGestureRecognizer类是个抽象类,下面的子类是具体的手势,开发这可以直接使用这些手势识别. UITapGestureRecognizer UIPinchGestureRecognizer UIRotationGestureRecog

iOS 手势UIGestureRecognizer

在 iPhone 或 iPad 的开发中,除了用 touchesBegan / touchesMoved / touchesEnded 这组方法来控制使用者的手指触控外,也可以用 UIGestureRecognizer 的衍生类別来进行判断.用 UIGestureRecognizer 的好处在于有现成的手势,开发者不用自己计算手指移动轨迹.UIGestureRecognizer的衍生类別有以下几种: UITapGestureRecognizer UIPinchGestureRecognizer

iOS手势学习UIGestureRecognizer & cocos2d 手势推荐

iOS手势学习UIGestureRecognizer & cocos2d 手势推荐 手势识别类型: UILongPressGestureRecognizer  // 长按UIPanGestureRecognizer  // 慢速拖动UIPinchGestureRecognizer  // 两指向內或向外拨动UIRotationGestureRecognizer   // 旋转UISwipeGestureRecognizer   // 快速滑动UITapGestureRecognizer   //

IOS开发之手势—UIGestureRecognizer 共存

IOS开发之手势--UIGestureRecognizer 共存 在 iPhone 或 iPad 的开发中,除了用 touchesBegan / touchesMoved / touchesEnded 这组方法来控制使用者的手指触控外,也可以用 UIGestureRecognizer 的衍生类別来进行判断.用 UIGestureRecognizer 的好处在于有现成的手势,开发者不用自己计算手指移动轨迹.UIGestureRecognizer的衍生类別有以下几种: UITapGestureRec

iOS手势 规避同一界面上不同子界面同时响应多个手势

最近在项目中遇到这样一个有关iOS手势的问题,首先需求描述如下:“在一个CollectionView中,要求长按不同的cell,产生一个cell的snapshot,此时可拖拽这个snapshot再进行后续的操作(如拖到view的某个位置出发一个事件)”.需求本身并不复杂,但要求每次只能有一个cell响应长按手势,不允许同时有两个或以上的cell响应长按手势. 我们知道UIGestureRecognizer有很多回调和方法可以兼容同一个View上的多种手势,网上相关的教程也很多,比如: http:

iOS 手势冲突

UITableView以及ScrollView不能相迎TouchBegin处理 IOS开发之手势--UIGestureRecognizer 共存 // 关键在这一行,如果双击确定偵測失败才會触发单击 [singleRecognizer requireGestureRecognizerToFail:doubleRecognizer]; 关于UIScrollView不能响应UITouch事件的解决办法 覆盖touch事件 ios的手势操作之UIGestureRecognizer浅析 UITapGes

iOS 手势识别器概述

手势识别器 iOS 手势识别器(UIGestureRecognizer) 点击手势(UITapGestureRecognizer) 滑动手势(UISwipeGestureRecognizer) 旋转手势(UIRotationGestureRecognizer) 捏合手势( UIPinchGestureRecognizer) 长按手势( UILongPressGestureRecognizer) 平移手势( UIPanGestureRecognizer) 屏幕边缘平移手势(UIScreenEdge

iOS手势处理

iOS手势处理 iOS手势有着如下几种: UITapGestureRecognizer UIPinchGestureRecognizer UIRotationGestureRecognizer UISwipeGestureRecognizer UIPanGestureRecognizer UILongPressGestureRecognizer 上面的手势对应的操作是: Tap          (点一下) Pinch        (二指往內或往外拨动,平时经常用到的缩放)  矩阵变换 Rot

iOS手势识别器

UIGestureRecognizer UIGestureRecognizer类,用于检测.识别用户使用设备时所用的手势.它是一个抽象类,定义了所有手势的基本行为.以下是UIGestureRecognizer子类,用于处理具体的用户手势行为: UITapGestureRecognizer // 1.单击 UILongPressGestureRecognizer // 3.长按 UISwipeGestureRecognizer // 4.轻扫 UIPanGestureRecognizer // 5