iOS(总结)手势

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;



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值