UI手势

UIGestureRecongnizer:NSObject

1.-(void)addGestureRecognizer:

(UIGestureRecognizer *)gestureRecognizer 附加一个手势识别器到视图

点击tap

UITapGestureRecognizer: UIGestureRecognizer

1.创建一个UITapGestureRecognizer对象

UITapGestureRecognizer * tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(tapAction:)];

2.numberOfTapsRequired 按几次触发

例:tap.numberOfTapsRequired = 2;

3.numberOfTouchesRequired 几根手指触发

例:tap.numberOfTouchesRequired = 2;

长按longpress

UILongPressGestureRecognizer:UIGestureRecognizer

1.创建一个UILongPressGestureRecognizer对象

UILongPressGestureRecognizer * longPress = [[UILongPRessGestureRecognizer alloc]initWithTarget:self action:@selector(longPress:)];

2.minimumPressDuration判定长按需要的时间 默认为0.5s

例:longPress.minimumPressDuration = 1;

3.allowableMovement 允许长按过程中移动的像素 默认10

例: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 滑动方向

例:swipe.direction = UISwipeGestureRecognizerDirectionLeft;

3.numberOfTouchesRequired 几根手指触发

旋转rotation

UIRotationGestureRecognizer:

UIGestureRecognizer

1.创建一个UIRotationGestureRecognizer对象

UIRotationGestureRecognizer *rotation = [[UIRotationGestureRecognizer alloc]initWithTarget:self action:@selector(rotation:)];

2.rotation 旋转速度

3.常用绑定方法

NSLog(@“旋转”);

UIView * view = rotation.view//获得当前手势所在的view

view.transform =

CGAffineTransformRotate(view.transform,rotation.rotation);//transform属性

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比例

例:pinch.scale =1;

屏幕边缘拖拽screenEdgePan

UIScreenEdgePanGestureRecognizer:UIPanGestureRecognizer

1.创建一个UIScreenEdgePanGestureRecognizer对象

UIScreenEdgePanGestureRecognizer * ScreenEdgePan = [[UIScreenEdgePanGestureRecognizer]initWithTarget:self action:@selector(screenEdgePan:)];

你可能感兴趣的:(UI手势)