1.UITapGestureRecognizer
1).点击手势,手势不是视图,不能显示在界面上,手势满足条件后调用的方法,第二个参数,
UITapGestureRecognizer *g = [[UITapGestureRecognizeralloc]initWithTarget:selfaction:@selector(tap:)];
2).点击的次数,必须连续点击两次
g.numberOfTapsRequired =2;
3).手指点击的个数,有几个手指
g.numberOfTouchesRequired =2;
4).使用手势,关联一个视图对象
[self.viewaddGestureRecognizer:g];//将手势加到vie上
2.UISwipeGestureRecognizer
1).滑动手势是一个,默认是横向滑动
UISwipeGestureRecognizer *sW = [[UISwipeGestureRecognizeralloc]initWithTarget:selfaction:@selector(swip:)];
sW.direction =UISwipeGestureRecognizerDirectionLeft|UISwipeGestureRecognizerDirectionRight;
2).只能左或者又,上或者下,如果想全部都有,在添加一个手势即可
[self.viewaddGestureRecognizer:sW];
3).添加一个上下的手势
UISwipeGestureRecognizer *sD = [[UISwipeGestureRecognizeralloc]initWithTarget:selfaction:@selector(SD:)];
sD.direction =UISwipeGestureRecognizerDirectionDown|UISwipeGestureRecognizerDirectionUp;
[self.viewaddGestureRecognizer:sD];
3.UILongPressGestureRecognizer
1).长按手势
UILongPressGestureRecognizer *lP = [[UILongPressGestureRecognizeralloc]initWithTarget:selfaction:@selector(longPress:)];
2).点击两次,次数设置不可以
lP.numberOfTapsRequired = 2;
3).手指个数
lP.numberOfTouchesRequired =2;
[self.viewaddGestureRecognizer:lP];
关联到视图对象
4.UIRotationGestureRecognizer
UIView *view = [[UIViewalloc]initWithFrame:CGRectMake(10,100, 300, 300)];
view.backgroundColor = [UIColorredColor];
[self.viewaddSubview: view];
1).添加一个可以旋转的手势
UIRotationGestureRecognizer *rota = [[UIRotationGestureRecognizeralloc]initWithTarget:selfaction:@selector(rotationM:)];
[view addGestureRecognizer:rota];
关联到红色视图上
2).方法中
==—1获取到手势关联的对象
UIView *views = rotas.view;
==—2获取旋转的角度
CGFloat angle = rotas.rotation ;
==-3旋转操作,参数是旋转的角度
views.transform =CGAffineTransformMakeRotation(angle);
5. UIPanGestureRecognizer
1).创建一个uilabel
UILabel *label = [[UILabelalloc]initWithFrame:CGRectMake(50,100, 100, 40)];
label.text =@"标签";
label.backgroundColor = [UIColorredColor];
[self.viewaddSubview:label];
2).添加一个移动的手势
UIPanGestureRecognizer *pan = [[UIPanGestureRecognizeralloc]initWithTarget:selfaction:@selector(panAction:)];
label.userInteractionEnabled =YES;
3).关联到label上
[label addGestureRecognizer:pan];
4).方法
UILabel *label = (UILabel *)pan.view;
==-1获取偏移量
CGPoint offsetPoint = [pan translationInView:self.view];
==-2修改位置
CGPoint oldCenter = label.center;
label.center =CGPointMake(oldCenter.x + offsetPoint.x, oldCenter.y + offsetPoint.y);
[pan setTranslation:CGPointZeroinView:self.view];
==-3将偏移量置为0
6.UIPinchGestureRecognizer
UIView *view = [[UIViewalloc]initWithFrame:CGRectMake(10,100, 300, 350)];
view.backgroundColor = [UIColorredColor];
[self.viewaddSubview: view];
1).添加手势.捏合手势
UIPinchGestureRecognizer *pinch = [[UIPinchGestureRecognizeralloc]initWithTarget:selfaction:@selector(pinchAction:)];
[view addGestureRecognizer:pinch];
关联到红色视图上
放大
==-1获取关联的视图
UIView *redView = pinch.view;
==-2放大的值
CGFloat scale = pinch.scale;
==-3修改transform属性,第二个是放大的倍数,第一个是原来的transform
redView.transform = CGAffineTransformScale(redView, scale, scale);
redView.transform =CGAffineTransformScale(redView.transform, scale, scale);
==-4恢复原值
pinch.scale =1;