zoukankan      html  css  js  c++  java
  • 关于手势 UIGestureRecognizer

    UIGestureRecognizer基类是一个抽象类,我们主要是使用它的子类:

    从名字上我们就能知道,Tap(点击)、Pinch(捏合)、Rotation(旋转)、Swipe(滑动,快速移动,是用于监测滑动的方向的)、Pan (拖移,慢速移动,是用于监测偏移的量的)以及 LongPress(长按).

    不过有些手势是关联的,怎么办呢?例如 Tap 与 LongPress、Swipe与 Pan,或是 Tap 一次与Tap 兩次。

    手势识别是具有互斥的原则的比如单击和双击,如果它识别出一种手势,其后的手势将不被识别。所以对于关联手势,要做特殊处理以帮助程序甄别,应该把当前手势归结到哪一类手势里面。

    比如,单击和双击并存时,如果不做处理,它就只能发送出单击的消息。为了能够识别出双击手势,就需要做一个特殊处理逻辑,即先判断手势是否是双击,在双击失效的情况下作为单击手势处理。使用

    [A requireGestureRecognizerToFail:B]函数,它可以指定当A手势发生时,即便A已经滿足条件了,也不会立刻触发会等到指定的手势B确定失败之后才触发。

    - (void)viewDidLoad
    {
    // 单击的 Recognizer
    UITapGestureRecognizer* singleRecognizer;
    singleRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:selfaction:@selector(SingleTap:)];
    //点击的次数
    singleTapRecognizer.numberOfTapsRequired = 1;// 单击
    //给self.view添加一个手势监测;
    [self.view addGestureRecognizer:singleRecognizer];
    // 双击的 Recognizer
    UITapGestureRecognizer* doubleRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:selfaction:@selector(DoubleTap:)];
    doubleRecognizer.numberOfTapsRequired = 2;// 双击
    //关键语句,给self.view添加一个手势监测;
    [self.view addGestureRecognizer:doubleRecognizer];
    // 关键在这一行,双击手势确定监测失败才会触发单击手势的相应操作
    [singleRecognizer requireGestureRecognizerToFail:doubleRecognizer];
    [singleRecognizer release];
    [doubleRecognizer release];
    }
    
    -(void)SingleTap:(UITapGestureRecognizer*)recognizer
    {
    //处理单击操作
    }
    
    -(void)DoubleTap:(UITapGestureRecognizer*)recognizer
    {
    //处理双击操作
    }
    
  • 相关阅读:
    php配置COM组件正常运行
    调试python程序
    git 较基础命令
    学习一下参数初始化
    谈谈pooling?
    Caffe 源碼閱讀(六) InternalThread
    Caffe 源碼閱讀(六) data_layer.cpp
    Caffe 源碼閱讀(五) Solver.cpp
    Caffe.proto使用
    Caffe 源碼閱讀(四) Layer.hpp Layer.cpp
  • 原文地址:https://www.cnblogs.com/Crazy-ZY/p/10613205.html
Copyright © 2011-2022 走看看