`

sdk 3.0 手势事件

 
阅读更多

一:手势事件类型

 

1.父类

UIGestureRecognizer 是一个抽象类,是所有手势事件的父类。

 

The concrete subclasses of UIGestureRecognizer are the following:

 

UITapGestureRecognizer  //轻拍
UIPinchGestureRecognizer //捏合
UIRotationGestureRecognizer //旋转
UISwipeGestureRecognizer  //扫
UIPanGestureRecognizer//拖拽
UILongPressGestureRecognizer //长按

 

2,如何添加手势事件及响应

 

(1)添加:调用 UIVIEW及其子类的  addGestureRecognizer:

(2)响应函数样式比如是下面两种的一种形式

- (void)handleGesture;
- (void)handleGesture:(UIGestureRecognizer *)gestureRecognizer;

 

     

- (void)viewDidLoad {
//---tap gesture---
UITapGestureRecognizer *tapGesture =[[UITapGestureRecognizer alloc]
initWithTarget:self
action:@selector(handleTapGesture:)];
tapGesture.numberOfTapsRequired = 2;
[imageView addGestureRecognizer:tapGesture];
[tapGesture release];
[super viewDidLoad];
}
//---handle tap gesture---
-(IBAction) handleTapGesture:(UIGestureRecognizer *) sender {
if (sender.view.contentMode == UIViewContentModeScaleAspectFit)
sender.view.contentMode = UIViewContentModeCenter;
else
sender.view.contentMode = UIViewContentModeScaleAspectFit;
}

 

3。

UITapGestureRecognizer 

       numberOfTapsRequired  :设置轻击的次数,默认值为1


       numberOfTouchesRequired  :触点的数量,默认值为1,即手指数

 

UIPinchGestureRecognizer

     当两个手指靠近表示zoom-in,当两个手指分离表示zoom-out。

           scale  

@property(nonatomic) CGFloat scale,放大缩小因子


           velocity 

@property(nonatomic, readonly) CGFloat velocity  ,只读属性 ,表示移动速度

 

UIRotationGestureRecognizer

 

       rotation  :旋转角度
       velocity  :速度

 

UISwipeGestureRecognizer 

  direction  :扫动方向,默认值UISwipeGestureRecognizerDirectionRight

 

typedef enum {
   UISwipeGestureRecognizerDirectionRight = 1 << 0,
   UISwipeGestureRecognizerDirectionLeft  = 1 << 1,
   UISwipeGestureRecognizerDirectionUp    = 1 << 2,
   UISwipeGestureRecognizerDirectionDown  = 1 << 3
} UISwipeGestureRecognizerDirection;

 


  numberOfTouchesRequired : 触点的数量,默认值为1,即手指数

 

 

UIPanGestureRecognizer

 

  maximumNumberOfTouches  :最大触摸的数量
  minimumNumberOfTouches  :最少触摸的数量

 

– translationInView:

A point identifying the new location of a view in the coordinate system of its designated superview.

一个点确定一个新的位置其指定的父视图的坐标系统


– setTranslation:inView:

 

 

The velocity of the pan gesture, which is expressed in points per second. The velocity is broken into horizontal and vertical components.

手势的速度这是表示在每分每秒速度分解为水平和垂直分量
– velocityInView:

- (CGPoint)velocityInView:(UIView *)view

 

UILongPressGestureRecognizer

 

  minimumPressDuration  :长按最短的时间
  numberOfTouchesRequired  :
  numberOfTapsRequired  :
  allowableMovement  :长按时运行移动的最大距离,默认值为10个像素

 

 

 

 

手指事件生命周期(状态)

 

取得当前手势状态

@property(nonatomic,readwrite) UIGestureRecognizerState state;

 

 

 

 

 

Possible ----> Began ----> [Changed] ----> Cancelled
Possible ----> Began ----> [Changed] ----> Ended

 

 

typedef enum {    

UIGestureRecognizerStatePossible,     

      UIGestureRecognizerStateBegan,     

 UIGestureRecognizerStateChanged,    

  UIGestureRecognizerStateEnded,     

 UIGestureRecognizerStateCancelled,   

        UIGestureRecognizerStateFailed,     

      UIGestureRecognizerStateRecognized = UIGestureRecognizerStateEnded  } UIGestureRecognizerState;

 

 

 

 

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics