标签:
1 typedef NS_ENUM(NSInteger, UIGestureRecognizerState) { 2 // 没有触摸事件发生,所有手势识别的默认状态 3 UIGestureRecognizerStatePossible, 4 // 一个手势已经开始但尚未改变或者完成时 5 UIGestureRecognizerStateBegan, 6 // 手势状态改变 7 UIGestureRecognizerStateChanged, 8 // 手势完成 9 UIGestureRecognizerStateEnded, 10 // 手势取消,恢复至Possible状态 11 UIGestureRecognizerStateCancelled, 12 // 手势失败,恢复至Possible状态 13 UIGestureRecognizerStateFailed, 14 // 识别到手势识别 15 UIGestureRecognizerStateRecognized = UIGestureRecognizerStateEnded 16 };
1 //创建手势识别器对象 2 UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] init]; 3 //设置手势识别器对象的具体属性 4 // 连续敲击2次 5 tap.numberOfTapsRequired = 2; 6 // 需要2根手指一起敲击 7 tap.numberOfTouchesRequired = 2; 8 //添加手势识别器到对应的view上 9 [self.iconView addGestureRecognizer:tap]; 10 //监听手势的触发 11 [tap addTarget:self action:@selector(tapIconView:)];
敲击手势--UITapGestureRecognizer
1 @property (nonatomic) NSUInteger numberOfTapsRequired; //敲击次数,默认是1 2 @property (nonatomic) NSUInteger numberOfTouchesRequired;//多点敲击,默认是1
1 - (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch;//是否接受触摸事件
1 @property (nonatomic) CFTimeInterval minimumPressDuration; //长按的时间,默认是0.5. 2 @property (nonatomic) CGFloat allowableMovement; //触摸点周围多远的距离内长按有效,默认是50(CGPoint)
1 @property(nonatomic) UISwipeGestureRecognizerDirection direction; //轻扫的方向,是一个枚举型
1 typedef NS_OPTIONS(NSUInteger, UISwipeGestureRecognizerDirection) { 2 UISwipeGestureRecognizerDirectionRight = 1 << 0,//向右轻扫,默认为向右轻扫 3 UISwipeGestureRecognizerDirectionLeft = 1 << 1,//向左轻扫 4 UISwipeGestureRecognizerDirectionUp = 1 << 2,//向上轻扫 5 UISwipeGestureRecognizerDirectionDown = 1 << 3//向下轻扫 6 };
1 @property (nonatomic) CGFloat scale; //缩放比例,是一个累加的过程,如果想不累加,把scale设为1即可 2 //例子: 3 - (void)pinvhView:(UIPinchGestureRecognizer *)pinch { 4 self.pinView.transform = CGAffineTransformScale(self.pinView.transform,pinch.scale,pinch.scale); 5 pinch.scale = 1; 6 }
1 @property (nonatomic) CGFloat rotation; //旋转角度,也是一个累加的过程,如果想它不累加,把其设为0即可。 2 //例子 3 - (void)rotationView:(UIRotationGestureRecognizer *)pinch { 4 self.pinView.transform = CGAffineTransformRotate(self.pinView.transform,pinch.rotation); 5 pinch.rotation = 0; 6 }
1 - (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer;//实现该方法,返回YES即可,允许跟其它手势一起发生
拖拽手势--UIPanGestureRecognizer
拖拽手势对象相关方法和属性:1 @property (nonatomic) NSUInteger minimumNumberOfTouches; // default is 1. the minimum number of touches required to match 2 @property (nonatomic) NSUInteger maximumNumberOfTouches; // default is UINT_MAX. the maximum number of touches that can be down 3 4 - (CGPoint)translationInView:(UIView *)view; // translation in the coordinate system of the specified view 5 - (void)setTranslation:(CGPoint)translation inView:(UIView *)view; 6 7 - (CGPoint)velocityInView:(UIView *)view; // velocity of the pan in pixels/second in the coordinate system of the specified view
标签:
原文地址:http://www.cnblogs.com/xiaomoge/p/4204889.html