滑动手势也算是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. UOJ.41.[清华集训2014]矩阵变换(稳定婚姻)

    题目链接 稳定婚姻问题:有n个男生n个女生,每个男/女生对每个女/男生有一个不同的喜爱程度.给每个人选择配偶. 若不存在 x,y未匹配,且x喜欢y胜过喜欢x当前的配偶,y喜欢x也胜过y当前的配偶 的完 ...

  2. BZOJ.1076.[SCOI2008]奖励关(概率DP 倒推)

    题目链接 BZOJ 洛谷 真的题意不明啊.. \(Description\) 你有k次选择的机会,每次将从n种物品中随机一件给你,你可以选择选或不选.选择它会获得这种物品的价值:选择一件物品前需要先选 ...

  3. Codeforces Round #372 (Div. 1) A. Plus and Square Root 数学题

    A. Plus and Square Root 题目连接: http://codeforces.com/contest/715/problem/A Description ZS the Coder i ...

  4. hdu 5742 It's All In The Mind 水题

    It's All In The Mind 题目连接: http://acm.hdu.edu.cn/showproblem.php?pid=5742 Description Professor Zhan ...

  5. Xcode 模拟器复制解决方案

    网址:http://blog.csdn.net/zhangao0086/article/details/38491271

  6. C# 读带复选框的excel,写excel并设置字体、边框、背景色

    这是一篇excel读写功能大汇总,通过C#调用Microsoft.Office.Interop.Excel.dll才能完成任何复杂格式excel的读写操作. 本文需要读取的excel格式如下: 可见表 ...

  7. 奇妙的 CSS shapes(CSS图形) 【css 图形,绘图,CSS 几何图形)】

    http://www.cnblogs.com/coco1s/p/6992177.html <!DOCTYPE html> <html> <head> <met ...

  8. Make the DbContext Ambient with UnitOfWorkScope(now named DbContextScope by mehdime)

    The Entity Framework DbContext (or LINQ-to-SQL DataContext) is a Unit Of Work implementation. That m ...

  9. Task Parallel Library01,基本用法

    我们知道,每个应用程序就是一个进程,一个进程有多个线程.Task Parallel Library为我们的异步编程.多线程编程提供了强有力的支持,它允许一个主线程运行的同时,另外的一些线程或Task也 ...

  10. 让DELPHI自带的richedit控件显示图片

    让DELPHI自带的richedit控件显示图片 unit RichEx; { 2005-03-04 LiChengbin Added: Insert bitmap or gif into RichE ...