UILongPressGestureRecognizer的介绍

    首先UILongPressGestureRecognizer是继承自UIGestureRecognizer 所有的手势都是继承自UIGestureRecognizer


  UIView *longPressView = [[UIView alloc]init];

  longPressView.backgroundColor = [UIColor redColor];

  longPressView.frame = CGRectMake(100, 200, 100, 100);

  [self.view addSubview:longPressView];


     创建一个长按的手势  这个方法是UIGestureRecognizer的方法

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


  为这个view添加手势

  [self.view addGestureRecognizer:longPress];

 


  longPress.minimumPressDuration = 4;

  The minimum period fingers must press on the view for the gesture to be recognized.

  设置长按手势 最低多少秒后触发的时间,默认的是0.5 这个数值是按秒计算的



  longPress.numberOfTouchesRequired = 1;

  The number of fingers that must be pressed on the view for the gesture to be recognized

  设置几个手指来触发这个长按手势 默认是1 一般都是1  若为0 则不触发



  longPress.numberOfTapsRequired = 0;

   The number of taps on the view required for the gesture to be recognized

   在这个view上手势需要识别轻敲击的次数 设置为1 就以为着连续快速的点击1次离开屏幕在迅速的点击这个view长按 不放到minimumPressDuration  才会触发手势的方法

   默认是0 就是按住不放 不需要离开屏幕


  longPress.allowableMovement = 20;

  The maximum movement of the fingers on the view before the gesture fails

  这个属性不是手势开始之后滑动的最大距离 只要UIGestureRecognizerStateBegan 你可以滑动任意大的距离

  这是属性是刚刚开始触摸view的时候到UIGestureRecognizerStateBegan这时时间内 最大的滑动距离

  默认是10



这个方法是触发这个手势后进入的方法 有兴趣的孩纸可以玩玩 

-(void)longPress:(UILongPressGestureRecognizer *)longPress{

  

  if (longPress.state == UIGestureRecognizerStateBegan) {

    

    NSLog(@"longPressBegan");

    

  }else if (longPress.state == UIGestureRecognizerStateChanged){

    

    NSLog(@"longPressChange");

    

  }else if (longPress.state == UIGestureRecognizerStateEnded){

    

    NSLog(@"end");

    

  }

  

}








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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值