zoukankan      html  css  js  c++  java
  • iOS 同一个View识别单击和双击手势

    1.给View添加手势

    //view添加两个手势检测方法
        self.currentPlayerView.userInteractionEnabled = YES;
        UITapGestureRecognizer *singleTapGesture = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(handleSingleTap:)];
        singleTapGesture.numberOfTapsRequired =1;
        singleTapGesture.numberOfTouchesRequired  =1;
        [self.currentPlayerView addGestureRecognizer:singleTapGesture];
        
        UITapGestureRecognizer *doubleTapGesture = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(handleDoubleTap:)];
        doubleTapGesture.numberOfTapsRequired =2;
        doubleTapGesture.numberOfTouchesRequired =1;
        //只有当doubleTapGesture识别失败的时候(即识别出这不是双击操作),singleTapGesture才能开始识别
        [singleTapGesture requireGestureRecognizerToFail:doubleTapGesture];
        [self.currentPlayerView addGestureRecognizer:doubleTapGesture];

    2.两个手势事件分别 区分单击了 还是双击了

    //两个手势分别响应的方法
    -(void)handleSingleTap:(UIGestureRecognizer *)sender{
        NSLog(@"单击--------------");
    }
    
    -(void)handleDoubleTap:(UIGestureRecognizer *)sender{
        NSLog(@"双击-------------- ");
    }

    参考文章地址 :https://www.jianshu.com/p/cdcde32cb252

  • 相关阅读:
    hibernate联合主键 注解方式
    使用Json出现java.lang.NoClassDefFoundError解决方法
    Spring 定时任务2
    Spring 定时任务1
    Javasocket1
    volatile
    Java中byte与16进制字符串的互相转换
    Spring 源码学习
    web服务器工作原理
    SpringMVC国际化
  • 原文地址:https://www.cnblogs.com/dujiahong/p/8898549.html
Copyright © 2011-2022 走看看