转自: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. PhoneGap开发的android项目环境搭建简单流程

      首先已经下载好最新的PhoneGap源代码. 已经装eclipse,android sdk及adt的安装和配置. 1.进入eclipse界面,新建android工程 new > androi ...

  2. css 如何使图片与文字在div中居中展示?

      1.情景展示 如何将图片与文字在div中一起居中展示? HTML片段 <div style="background: #fff;padding-top: 5px;border:1p ...

  3. django生成文件txt、pdf(在生成 PDF 文件之前,需要安装 ReportLab 库)

    from django.http import HttpResponse def download_file(request): # Text file #response = HttpRespons ...

  4. python之实现ftp上传下载代码(含错误处理)

    # -*- coding: utf-8 -*- #python 27 #xiaodeng #python之实现ftp上传下载代码(含错误处理) #http://www.cnblogs.com/kait ...

  5. jQuery操作radio、checkbox、select总结

    1.radio:单选框 HTML代码: <input type="radio" name="radio" id="radio1" va ...

  6. ansible2.4.x RPM急速安装

    概述: 在centos上安装ansible如果在线联网安装甚是方便,实际上大部分在内网安装隔绝外网,都是离线安装.如何急速安装软件,使我们迫切的愿望 环境: python2.6 ansible2.4. ...

  7. &lt;十一&gt;读&lt;&lt;大话设计模式&gt;&gt;之抽象工厂模式

    学习设计模式有一段时间了,对设计模式有一个体会,就是没那么难.就是设计程序遵循一些原则,让代码可复用,在改动的时候不用涉及太多的类,扩展方便.抽象工厂模式名字听起来抽象.但理解起来一点也不抽象,用语言 ...

  8. SG 函数初步 HDU 1536 &amp;&amp; HDU 1944

    题目链接:http://acm.hdu.edu.cn/showproblem.php? pid=1944 pid=1536"> http://acm.hdu.edu.cn/showpr ...

  9. Uploadify in ASP.Net

    和分页类似,文件上传是web开发标配的技能之一.下面介绍Uploadify的配置和使用. 一.配置 首先到Uploadify官网下载,然后在项目中添加相应引用.前台代码如下: 1.jquery.js2 ...

  10. easyui的datagrid分页写法小结

    easyui的datagrid分页死活不起作用...沙雕了...不说了上代码 //关闭tab1打开tab2 查询Detail function refundDetail(){ $('#tt').tab ...