转自:http://blog.163.com/china_uv/blog/static/117137267201252102612185/

UISwipeGestureRecognizer 左右事件相同为非注释代码, 左右事件不同为注释代码。

@implementation GestureRecognizerViewController

-(id)init
{
    if (self == [super init]) {
        
        UISwipeGestureRecognizer *recognizer;    
        recognizer = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(handleSwipeFrom:)];    
        [recognizer setDirection:UISwipeGestureRecognizerDirectionLeft|UISwipeGestureRecognizerDirectionRight];
        [[self view] addGestureRecognizer:recognizer];    
        [recognizer release];
        
//        recognizer = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(handleSwipeFrom:)];    
//        [recognizer setDirection:UISwipeGestureRecognizerDirectionLeft];
//        [[self view] addGestureRecognizer:recognizer];    
//        [recognizer release];
//        
//        recognizer = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(handleSwipeFrom:)];    
//        [recognizer setDirection:UISwipeGestureRecognizerDirectionRight];
//        [[self view] addGestureRecognizer:recognizer];    
//        [recognizer release];
        
    }
    
    return self;
}

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    
    self.view.backgroundColor = [UIColor darkGrayColor];
}

- (void)viewDidUnload
{
    [super viewDidUnload];
    // Release any retained subviews of the main view.
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}

-(void) dealloc
{
    for (UISwipeGestureRecognizer *recognizer in [[self view] gestureRecognizers]) {  
        [[self view] removeGestureRecognizer:recognizer];  
    } 
    
    [super dealloc];
}

// ------------------------------------------------------------------------

- (void)handleSwipeFrom:(UISwipeGestureRecognizer *)recognizer{    
    
    NSLog(@"direction ------------- %d", recognizer.direction);
    
    
    if (recognizer.direction == (UISwipeGestureRecognizerDirectionLeft | UISwipeGestureRecognizerDirectionRight)) {    
        NSLog(@"left & right");  
    }
    
//    if (UISwipeGestureRecognizerDirectionLeft == recognizer.direction) {    
//        NSLog(@"left");  
//    }
//    
//    if (UISwipeGestureRecognizerDirectionRight == recognizer.direction) {    
//        NSLog(@"right");  
//    }
}

感叹下IOS的智慧,UISwipeGestureRecognizerDirection定义用的是位移。
typedef enum {
    UISwipeGestureRecognizerDirectionRight = 1 << 0,
    UISwipeGestureRecognizerDirectionLeft  = 1 << 1,
    UISwipeGestureRecognizerDirectionUp    = 1 << 2,
    UISwipeGestureRecognizerDirectionDown  = 1 << 3
} UISwipeGestureRecognizerDirection;

UISwipeGestureRecognizer 左右事件捕捉的更多相关文章

  1. 事件冒泡(event bubbling)与事件捕捉(event capturing)

    事件捕捉: 单击<div>元素就会以下列顺序触发click 事件. Document => Element html => Element body => Element ...

  2. Chromium网页输入事件捕捉和手势检測过程分析

    连续的输入事件可能会产生一定的手势操作.比如滑动手势和捏合手势. 在Chromium中,网页的输入事件是在Browser进程中捕捉的.Browser进程捕获输入事件之后,会进行手势操作检測.检測出来的 ...

  3. QT 托盘 hover事件捕捉

    1. QSystemTrayIcon hover事件 参考:https://stackoverflow.com/questions/21795919/how-to-catch-the-mousehov ...

  4. 谈事件冒泡(Bubble)和事件捕捉(capture)

    事件的发生顺序 假设在一个元素中又嵌套了另一个元素并且两者都有一个onClick事件处理函数(event handler).如果用户单击元素2,则元素1和元素2的单击事件都会被触发.但是哪一个事件先被 ...

  5. 【Delphi】最小化事件捕捉

    添加一个ApplicationEvents组件在窗体,然后处理其OnMinimize事件和OnRestore事件即可.

  6. js事件冒泡和事件捕捉

    结论:他们是描述事件触发时序问题的术语.事件捕获指的是从document到触发事件的那个节点,即自上而下的去触发事件.相反的,事件冒泡是自下而上的去触发事件.绑定事件方法的第三个参数,就是控制事件触发 ...

  7. js··事件捕捉

    给一个元素绑定事件,普通写法是 obj.onclick=function(){} 这就相当于给obj的onclick属性赋值是一个道理. obj.onclick=function(){} 这种写法有一 ...

  8. 模态框MODAL的一些事件捕捉

    下表列出了模态框中要用到事件.这些事件可在函数中当钩子使用. 事件 描述 实例 show.bs.modal 在调用 show 方法后触发. $('#identifier').on('show.bs.m ...

  9. javascript 区域外事件捕捉setCapture

    今天遇到了这个方法,便去度娘了解了下 函数功能:该函数在属于当前线程的指定窗口里设置鼠标捕获.一旦窗口捕获了鼠标,所有鼠标输入都针对该窗口,无论光标是否在窗口的边界内.同一时刻只能有一个窗口捕获鼠标. ...

随机推荐

  1. 〖Android〗JDK7签名apk出现INSTALL_PARSE_FAILED_NO_CERTIFICATES的解决方法

    由于某项需求,把JDK版本从JDK6升级到了JDK7: 但是签名APK之后出现了INSTALL_PARSE_FAILED_NO_CERTIFICATES的错误: 解决方法: 在签名时,添加参数 -di ...

  2. 面向对象高级——Object类、包装类以及匿名内部类

    Object类  知识点:掌握Object类的作用.掌握Object类中toString().equal()方法的作用 ,掌握Object接收引用数据类型的操作. 假设一个类在定义时没有明白指明继承哪 ...

  3. 如何快速的将一个str转换为list

    # -*- coding: cp936 -*- #python 27 #xiaodeng #如何快速的将一个str转换为list str='python' print list(str)#['p', ...

  4. windows下命令行终端使用rz上传文件参数详解

    rz命令: (X) = option applies to XMODEM only (Y) = option applies to YMODEM only (Z) = option applies t ...

  5. 批处理转exe工具(Quick Batch File Compiler )|bat格式化exe

    看到的,就是回忆.历史总是那么漫不经心,走完一生.留下可以记忆的脚本.... 对于window编写的bat脚本,想加密吗? 你所想的,前辈们基本上都有产出成果.所以在这个开源.共享.进步的互联网时代. ...

  6. C++基础学习教程(六)----类编写的前情回想以及项目实战(1)

    在開始类的编写之前我们依旧须要回想整理一下前面所说的内容,(前面尽管是一个自己定义数据类型的实现过程,可是内容有点繁杂). 先看一段代码: /** @file calssStruct.cpp */ / ...

  7. top 学习

    通常top命令是会持续运行而不终止的. 要在脚本里用,需要添加一些选项参数,尤其是-b.例如:top -b -n 2 -d 3 >/tmp/log -b表示批处理模式(Batch mode),以 ...

  8. PHP基本的语法以及和Java的差别

    .表示字符串相加 ->同Java中的. $作为变量的前缀,除此之外.变量名称定义规则同Java 參数传递和方法返回时传引用须要加前缀& 演示样例代码: function f(&$ ...

  9. 整合大量开源库项目(八)能够载入Gif动画的GifImageView

    转载请注明出处王亟亟的大牛之路 上周大多数时间都是依据兴起,想到什么做什么写了几个自己定义控件,把Soyi丢在那没怎么动,今天就把写的东西整合进来,顺便把SOyi"个人研发的结构理一下&qu ...

  10. css中position:fixed实现div居中

    上下左右 居中 代码如下 复制代码 div{ position:fixed; margin:auto; left:0; right:0; top:0; bottom:0; width:200px; h ...