zoukankan      html  css  js  c++  java
  • UITapGestureRecognizer 区分多指 单双击

    LINK ADDRESS:http://www.cocoachina.com/bbs/read.php?tid=73117&fpage=3

    前几天又有山大的MM问我,怎么区分单双击。
    我说到坛子里找,没过多久,她又说,用touches方法控制的单双击不太好用,还有什么事件冲突……
    没办法,帮忙写了一个,也发上来,知道的可掠过,需要的请自取。

     
    复制代码
    1. - (void)viewDidLoad {
    2.     
    3.     UITapGestureRecognizer *singleTapOne = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleSingleTap:)];
    4.     singleTapOne.numberOfTouchesRequired = 1; singleTapOne.numberOfTapsRequired = 1; singleTapOne.delegate = self;
    5.     
    6.     UITapGestureRecognizer *singleTapTwo = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleSingleTap:)];
    7.     singleTapTwo.numberOfTouchesRequired = 2; singleTapTwo.numberOfTapsRequired = 1; singleTapTwo.delegate = self;
    8.     
    9.     UITapGestureRecognizer *doubleTapOne = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleDoubleTap:)];
    10.     doubleTapOne.numberOfTouchesRequired = 1; doubleTapOne.numberOfTapsRequired = 2; doubleTapOne.delegate = self;
    11.     
    12.     UITapGestureRecognizer *doubleTapTwo = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleDoubleTap:)];
    13.     doubleTapTwo.numberOfTouchesRequired = 2; doubleTapTwo.numberOfTapsRequired = 2; doubleTapTwo.delegate = self;
    14.     
    15.     [singleTapOne requireGestureRecognizerToFail:doubleTapOne]; // Single tap requires double tap to fail
    16.     [singleTapTwo requireGestureRecognizerToFail:doubleTapTwo];
    17.     
    18.     [self.view addGestureRecognizer:singleTapOne]; [singleTapOne release];
    19.     [self.view addGestureRecognizer:singleTapTwo]; [singleTapTwo release];
    20.     [self.view addGestureRecognizer:doubleTapOne]; [doubleTapOne release];
    21.     [self.view addGestureRecognizer:doubleTapTwo]; [doubleTapTwo release];
    22.     
    23.     
    24.     [super viewDidLoad];
    25. }
    26. - (void)handleSingleTap:(UITapGestureRecognizer *)sender {
    27.     if (sender.numberOfTouchesRequired == 1) {
    28.         NSLog(@"Single Tap with a finger.");
    29.     }
    30.     else if (sender.numberOfTouchesRequired == 2) {
    31.         NSLog(@"Single Tap with two finger.");
    32.     }
    33. }
    34. - (void)handleDoubleTap:(UITapGestureRecognizer *)sender {
    35.     if (sender.numberOfTouchesRequired == 1) {
    36.         NSLog(@"Double Tap with a finger.");
    37.     }
    38.     else if (sender.numberOfTouchesRequired == 2) {
    39.         NSLog(@"Double Tap with two finger.");
    40.     }
    41. }
  • 相关阅读:
    LF.51.Insert In Binary Search Tree
    Use Array To Implement Queue With Size(bounded)
    Use LinkedList to implement Queue
    Use LinkedList to Implement Stack
    LT.11.Search Range In Binary Search Tree
    Odoo 12开发之后台视图 – 设计用户界面 ###
    Odoo 之业务逻辑
    Odoo开发之记录集 – 使用模型数据
    odoo 之 结构化应用数据
    odoo之数据导入导出以及模块数据
  • 原文地址:https://www.cnblogs.com/xingchen/p/2271415.html
Copyright © 2011-2022 走看看