滑动手势也算是iOS中交互中很重要的一部分,上下左右滑动,UISwipeGestureRecognizer可以很轻松的解决这个问题,没什么难度直接看代码吧:

    UISwipeGestureRecognizer  *upSwipeGestureRecognizer=[[UISwipeGestureRecognizer alloc]initWithTarget:self action:@selector(swipeGestureRecognizer:)];
upSwipeGestureRecognizer.direction=UISwipeGestureRecognizerDirectionUp;
[self.view addGestureRecognizer:upSwipeGestureRecognizer]; UISwipeGestureRecognizer *downSwipeGestureRecognizer=[[UISwipeGestureRecognizer alloc]initWithTarget:self action:@selector(swipeGestureRecognizer:)];
downSwipeGestureRecognizer.direction=UISwipeGestureRecognizerDirectionDown;
[self.view addGestureRecognizer:downSwipeGestureRecognizer]; UISwipeGestureRecognizer *leftSwipeGestureRecognizer=[[UISwipeGestureRecognizer alloc]initWithTarget:self action:@selector(swipeGestureRecognizer:)];
leftSwipeGestureRecognizer.direction=UISwipeGestureRecognizerDirectionLeft;
[self.view addGestureRecognizer:leftSwipeGestureRecognizer]; UISwipeGestureRecognizer *rightSwipeGestureRecognizer=[[UISwipeGestureRecognizer alloc]initWithTarget:self action:@selector(swipeGestureRecognizer:)];
rightSwipeGestureRecognizer.direction=UISwipeGestureRecognizerDirectionRight;
[self.view addGestureRecognizer:rightSwipeGestureRecognizer];

手势处理:

-(void)swipeGestureRecognizer:(UISwipeGestureRecognizer *)recongnizer{
if (recongnizer.direction==UISwipeGestureRecognizerDirectionUp) {
NSLog(@"向上滑动");
NSLog(@"博客园-FlyElephant");
} if (recongnizer.direction==UISwipeGestureRecognizerDirectionDown) {
NSLog(@"向下滑动");
NSLog(@"原文地址:http://www.cnblogs.com/xiaofeixiang");
} if (recongnizer.direction==UISwipeGestureRecognizerDirectionLeft) {
NSLog(@"向左滑动");
NSLog(@"iOS技术交流群:228407086");
} if (recongnizer.direction==UISwipeGestureRecognizerDirectionRight) {
NSLog(@"向右滑动");
}
}

效果图:

iOS开发-UISwipeGestureRecognizer滑动手势的更多相关文章

  1. 李洪强iOS开发之添加手势

    李洪强iOS开发之添加手势 02 - 添加手势

  2. iOS开发cell--滑动手势显示按钮

    // 主要代码 #warning iOS8 - #pragma mark 在滑动手势删除某一行的时候,显示出更多的按钮 - (NSArray *)tableView:(UITableView *)ta ...

  3. iOS开发UI高级手势识别器

    ####手势识别器 UIGestureRecognizer类 ·UITapGestureRecognizer(轻击) ·UIPinchGestureRecognizer(捏合) ·UIPanGestu ...

  4. IOS开发中滑动页面时NSTimer停止的问题

    我们在做倒计时的时候,发现当你手指按着屏幕不放,拖动tableView滑动的时候,写在cell上得倒计时停止倒计时,松开继续倒计时.研究发现就是拖动tableView滑动时,NSTimer停止了. 这 ...

  5. iOS开发 解决UITapGestureRecognizer手势与UITableView的点击事件的冲突

    该篇文章摘自我的新浪博客,原文地址为: http://blog.sina.com.cn/s/blog_dcc636350102wavx.html UITableView 拥有属于自己的点击事件,在将一 ...

  6. iOS开发-UITableView滑动视差

    视差滚动是指让多层背景以不同的速度移动,形成立体的运动效果,在Web上应用的比较多,App中倒是见的相对比较少,主要在UITableView中的应用的比较多,尤其是当整个UITableViewCell ...

  7. ios开发之滑动长图截全屏应用

    最近做项目遇到要求截取图片长度超出手机屏幕,即可滑动的长图截屏,这里简单说一下解决思路,下面附带Demo下载地址. ,当我们要截全屏时,将滑动视图的frame以及偏移量记录下来,然后将滑动视图偏移量设 ...

  8. iOS开发-iOS7禁用手势返回

    - (void)viewDidAppear:(BOOL)animated { [super viewDidAppear:animated]; // 禁用 iOS7 返回手势 if ([self.nav ...

  9. IOS开发之---触摸和手势

    Touch:在与设备的多点触摸屏交互时生成. 响应者对象 响应者对象就是可以响应事件并对事件作出处理.在iOS中,存在UIResponder类,它定义了响应者对象的所有方法.UIApplication ...

随机推荐

  1. POJ.1379.Run Away(模拟退火)

    题目链接 POJ输出不能用%lf! mmp从4:30改到6:00,把4:30交的一改输出也过了. 于是就有了两份代码.. //392K 500MS //用两点构成的矩形更新,就不需要管边界了 #inc ...

  2. [Java]Spring框架

    在这里学习Spring框架: >>spring&struts框架学习 >>spring >>Java回顾之Spring基础 >>IBM Java ...

  3. pygame系列_小球完全弹性碰撞游戏_源码下载

    之前做了一个基于python的tkinter的小球完全碰撞游戏: python开发_tkinter_小球完全弹性碰撞游戏_源码下载 今天利用业余时间,写了一个功能要强大一些的小球完全碰撞游戏: 游戏名 ...

  4. Intel Code Challenge Final Round (Div. 1 + Div. 2, Combined) A. Checking the Calendar 水题

    A. Checking the Calendar 题目连接: http://codeforces.com/contest/724/problem/A Description You are given ...

  5. hdu 5783 Divide the Sequence 贪心

    Divide the Sequence 题目连接: http://acm.hdu.edu.cn/showproblem.php?pid=5783 Description Alice has a seq ...

  6. haskell学习资料

    Haskell基础语法 Real World Haskell 中文版 Haskell趣学指南

  7. mysql慢查询日志功能的使用

    作用:mysql慢查询日志可监控有效率问题的SQL .. 一.开启mysql慢查询日志功能 1.查看是否开启 未使用索引的SQL记录日志查询 mysql> show variables like ...

  8. SWD Registers

  9. STM32CubeF4 FreeRTOS Examples don't work correctly with HAL_GetTick

    because the SysTick ISR has been assigned to the FreeRTOS xPortSysTickHandler() function without reg ...

  10. PGXZ-腾讯全功能分布式关系数据集群

    PGXZ-腾讯全功能分布式关系数据集群