手势种类
UIGestureRecognizer : NSObject
1.- (void)addGestureRecognizer:(UIGestureRecognizer*)gestureRecognizer
附加一个手势识别器到视图。
一.点击 tap
UITapGestureRecognizer : UIGestureRecognizer
1.创建一个UITapGestureRecognizer对象
UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(tapAction:)];
2.numberOfTapsRequired
按几次触发
eg:tap.numberOfTapsRequired = 2;
3.numberOfTouchesRequired
几根手指触发
eg:tap.numberOfTouchesRequired = 2;
二.长按 longpress
UILongPressGestureRecognizer : UIGestureRecognizer
1.创建一个UILongPressGestureRecognizer对象
UILongPressGestureRecognizer *longPress = [[UILongPressGestureRecognizer alloc]initWithTarget:self action:@selector(longPress:)];
2.minimumPressDuration
判定长按 需要的时间 默认为0.5s
eg:longPress.minimumPressDuration = 1;
3.allowableMovement
允许长按过程中移动的像素 默认10
eg:longPress.allowableMovement = 100;
4.常用绑定方法
if(longPress.state == UIGestureRecognizerStateBegan)
{
NSLog(@"长按");
}
三.清扫 swipe
UISwipeGestureRecognizer : UIGestureRecognizer
1.创建一个UISwipeGestureRecognizer对象
UISwipeGestureRecognizer *swipe = [[UISwipeGestureRecognizer alloc]initWithTarget:self action:@selector(swipe:)];
2.direction
滑动方向
eg:swipe.direction = UISwipeGestureRecognizerDirectionLeft;
3.numberOfTouchesRequired
几根手指触发
四.旋转 rotation
UIRotationGestureRecognizer : UIGestureRecognizer
1.创建一个UIRotationGestureRecognizer对象
UIRotationGestureRecognizer *rotation = [[UIRotationGestureRecognizer alloc]initWithTarget:self action:@selector(rotation:)];
2.rotation
旋转速度
3.常用绑定方法
NSLog(@"旋转");
//获得当前手势所在的view
UIView *view = rotation.view;
//transform属性
view.transform = CGAffineTransformRotate(view.transform, rotation.rotation);
rotation.rotation = 0;
五.拖拽 pan
UIPanGestureRecognizer : UIGestureRecognizer
1.创建一个UIPanGestureRecognizer对象
UIPanGestureRecognizer *pan = [[UIPanGestureRecognizer alloc]initWithTarget:self action:@selector(pan:)];
2.常用绑定方法
NSLog(@"拖拽");
CGPoint translation = [pan translationInView:self.view];
UIView *view = pan.view;
view.center = CGPointMake(view.center.x + translation.x, view.center.y + translation.y);
[pan setTranslation:CGPointMake(0, 0) inView:self.view];
六.捏合 pinch
UIPinchGestureRecognizer : UIGestureRecognizer
1.创建一个UIPinchGestureRecognizer对象
UIPinchGestureRecognizer *pinch = [[UIPinchGestureRecognizer alloc]initWithTarget:self action:@selector(pinch:)];
2.常用绑定方法
UIView *view = pinch.view;
view.transform = CGAffineTransformScale(view.transform, pinch.scale, pinch.scale);
3.scale
比例
eg:pinch.scale = 1;
七.屏幕边缘拖拽 screenEdgePan
UIScreenEdgePanGestureRecognizer : UIPanGestureRecognizer
1.创建一个UIScreenEdgePanGestureRecognizer对象
UIScreenEdgePanGestureRecognizer *screenEdgePan = [[UIScreenEdgePanGestureRecognizer alloc]initWithTarget:self action:@selector(screenEdgePan:)];