(边学边记录)UIGestureRecognizer

来源:互联网 发布:java住户信息管理系统 编辑:程序博客网 时间:2024/06/06 14:16



UIGestureRecognizer是一个具体的手势识别抽象类,我们主要是使用它的子类


UITapGestureRecognizer(点击,不连续手势)

UIPinchGestureRecognizer(捏合,没有移动距离属性,是一个缩放比例)

UIRotationGestureRecognizer(旋转)

UISwipeGestureRecognizer(滑动,快速移动,是用于监测滑动的方向的,不连续手势)

UIPanGestureRecognizer(拖移,慢速移动,是用于监测偏移的量的)

UILongPressGestureRecognizer(长按)


1.UIPanGestureRecognizer


常用方法:

-(CGPoint)translationInView:(UIView *)aView;

-(CGPoint)velocityInView:(UIView *)aView;

-(void)setTranslation:(CGPoint)translation inView(UIView *)aView;


属性:

@property (readonly) UIGestureRecognizerState state;

表示手指状态


UIGestureRecognizerStateBegan;

表示连续运动的手势(比如拖动或捏合),手指刚触碰到屏幕

UIGestureRecognizerStateChanged;

表示连续运动的手势,手指移动了

UIGestureRecognizerStateEnded;

手指抬离屏幕了

UIGestureRecognizerStateRecognized;

出现于不连续手势的情况(比如点击或滑动)

UIGestureRecognizerStateCancelled

UIGestureRecognizerStateFailed

手势中断


2.UIPinchGestureRecognizer


@property CGFloat scale;

表示缩放比例

@property (readonly) CGFloat velocity;

表示比例系数的变化速度,每秒钟变化多少


3.UIRotationGestureRecognizer


@property CGFloat rotation;

表示弧度信息

@property (readonly) CGFloat velocity;

表示比例系数的变化速度,每秒钟变化多少弧度


4.UISwipeGestureRecognizer


@property UISwipeGestureRecognizerDirection direction;

方向

@property NSUInteger numberOfTouchesRequired;

所需触控数量(这个滑动手势需要几根手指)


5.UITapGestureRecognizer


@property NSUInteger numberOfTapsRequired;

点击数量(单击还是双击Or更多)

@property NSUInteger numberOfTouchesRequired;

所需触控数量



1 0