码迷,mamicode.com
首页 > 移动开发 > 详细

iOS手势UIGestureRecognizer

时间:2014-08-29 18:25:58      阅读:213      评论:0      收藏:0      [点我收藏+]

标签: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

标签:ios   手势   uigesturerecognizer   

原文地址:http://blog.csdn.net/xdrt81y/article/details/38927125

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!