目前有三种方案:

1.

UIScrollView + UITableView。

实现方法,在UIScrollView中,加入UITableView即可

设置UIScrollView的代理和方法

- (void)scrollViewDidScroll:(UIScrollView *)scrollView{
int currentPostion = scrollView.contentOffset.x;
if (currentPostion - > ) {
NSLog(@"Scroll right now ");
}
else if ( - currentPostion > )
{
NSLog(@"Scroll left now");
}
}

2.利用UISwipeGestureRecognizer

原文地址:http://www.2cto.com/kf/201312/265158.html

-(void)viewDidLoad{

UISwipeGestureRecognizer *recognizer;

recognizer = [[UISwipeGestureRecognizer alloc]initWithTarget:self action:@selector(handleSwipeFrom:)];

[recognizer setDirection:(UISwipeGestureRecognizerDirectionRight)];

[[self view] addGestureRecognizer:recognizer];

recognizer = [[UISwipeGestureRecognizer alloc]initWithTarget:self action:@selector(handleSwipeFrom:)];

[recognizer setDirection:(UISwipeGestureRecognizerDirectionLeft)];

[[self view] addGestureRecognizer:recognizer];

recognizer = [[UISwipeGestureRecognizer alloc]initWithTarget:self action:@selector(handleSwipeFrom:)];

[recognizer setDirection:(UISwipeGestureRecognizerDirectionUp)];

[[self view] addGestureRecognizer:recognizer];

recognizer = [[UISwipeGestureRecognizer alloc]initWithTarget:self action:@selector(handleSwipeFrom:)];

[recognizer setDirection:(UISwipeGestureRecognizerDirectionDown)];

[[self view] addGestureRecognizer:recognizer];

}

-(void)handleSwipeFrom:(UISwipeGestureRecognizer *)recognizer{

if(recognizer.direction==UISwipeGestureRecognizerDirectionDown) {

NSLog(@"swipe down");

//执行程序

}

if(recognizer.direction==UISwipeGestureRecognizerDirectionUp) {

NSLog(@"swipe up");

//执行程序

}

if(recognizer.direction==UISwipeGestureRecognizerDirectionLeft) {

NSLog(@"swipe left");

//执行程序

}

if(recognizer.direction==UISwipeGestureRecognizerDirectionRight) {

NSLog(@"swipe right");

//执行程序

}

}

3.

原文地址:http://www.cppblog.com/Khan/archive/2013/02/27/198100.html

UITableView 屏蔽了左右滑动事件.  通过重载的方式可以注入事件touch事件, 供开发者使用..

 #import <UIKit/UIKit.h>
@protocol TouchTableViewDelegate <NSObject>
@optional
- (void)tableView:(UITableView *)tableView touchesBegin:(NSSet *)touches withEvent:(UIEvent *)event;
- (void)tableView:(UITableView *)tableView touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event;
- (void)tableView:(UITableView *)tableView touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event;
- (void)tableView:(UITableView *)tableView touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event;
@end

 #import "TouchTableView.h"

 @implementation TouchTableView

 @synthesize touchDelegate = _touchDelegate;

 - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
[super touchesBegan:touches withEvent:event]; if ([_touchDelegate conformsToProtocol:@protocol(TouchTableViewDelegate)] &&
[_touchDelegate respondsToSelector:@selector(tableView:touchesBegin:withEvent:)])
{
[_touchDelegate tableView:self touchesBegin:touches withEvent:event];
}
} - (void)touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event {
[super touchesCancelled:touches withEvent:event]; if ([_touchDelegate conformsToProtocol:@protocol(TouchTableViewDelegate)] &&
[_touchDelegate respondsToSelector:@selector(tableView:touchesCancelled:withEvent:)])
{
[_touchDelegate tableView:self touchesCancelled:touches withEvent:event];
}
} - (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
[super touchesEnded:touches withEvent:event]; if ([_touchDelegate conformsToProtocol:@protocol(TouchTableViewDelegate)] &&
[_touchDelegate respondsToSelector:@selector(tableView:touchesEnded:withEvent:)])
{
[_touchDelegate tableView:self touchesEnded:touches withEvent:event];
}
} - (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
[super touchesMoved:touches withEvent:event]; if ([_touchDelegate conformsToProtocol:@protocol(TouchTableViewDelegate)] &&
[_touchDelegate respondsToSelector:@selector(tableView:touchesMoved:withEvent:)])
{
[_touchDelegate tableView:self touchesMoved:touches withEvent:event];
}
} @end
 
调用方法 :
1. 头文件中加入delegate
@interface MoneyViewCtl : UIViewController<UITableViewDataSource, UITableViewDelegate, SDWebDataDownloaderDelegate, EGORefreshTableHeaderDelegate, TouchTableViewDelegate>{

    IBOutlet UISegmentedControl *_sigTime;

    IBOutlet TouchTableView *_tableview;

}

@end

2. .m文件中设置好delegate

_tableview.touchDelegate = self;

3. .m文件中实现如下事件

#pragma mark - TouchTableViewDelegate lifecycle

- (void)tableView:(UITableView *)tableView touchesBegin:(NSSet *)touches withEvent:(UIEvent *)event{

    NSLog(@"touchesBegin");

}

- (void)tableView:(UITableView *)tableView touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event{

    NSLog(@"touchesCancelled");

}

- (void)tableView:(UITableView *)tableView touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event{

    NSLog(@"touchesEnded");

}

- (void)tableView:(UITableView *)tableView touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event{

    NSLog(@"touchesMoved");

}

在UITableView中识别左右滑动,实现上下翻页的功能的更多相关文章

  1. js中的referrer使用,返回上一页

    js完整代码: <script language="javascript"> var refer=document. referrer ;     document.g ...

  2. linux中使sqlplus能够上下翻页

    安装包链接:https://pan.baidu.com/s/1WsQTeEQClM88aEqIvNi2ag 提取码:s241  rlwrap-0.37-1.el6.x86_64.rpm 和 rlwra ...

  3. linux vi编辑器中,如何通过快捷键上下翻页?

    需求说明: 之前在vi的时候,如果想看下一页,就直接按住 ↓ 这个箭头一直翻,现在觉得有些麻烦, 就找了下上,下翻页的快捷方式.在此记录下. 记录: 1.向下翻页快捷键(下一页):Ctrl + f 2 ...

  4. php实现返回上一页的功能

    php实现返回上一页的功能的3种有效方法 header(location:你的上一页的路径);   //   注意这个函数前不能有输出      header(location:.getenv(&qu ...

  5. rlwrap-0.37.tar.gz实现sqlplus上下翻页

    1.上传rlwrap-0.37.tar.gz到linux 2.解压rlwrap-0.37.tar.gz [root@node1 mnt]# tar zxvf rlwrap-0.37.tar.gz [r ...

  6. php实现返回上一页的功能的3种有效方法

    php实现返回上一页的功能的3种有效方法 header(location:你的上一页的路径);   //   注意这个函数前不能有输出 header(location:.getenv("HT ...

  7. Oracle管理监控之rlwrap-0.37.tar.gz实现sqlplus上下翻页

    1.上传rlwrap-0.37.tar.gz到linux 2.解压rlwrap-0.37.tar.gz [root@node1 mnt]# tar zxvf rlwrap-0.37.tar.gz [r ...

  8. android studio中Fragment使用webview返回上一页的问题

    在Fragment中使用了腾讯的X5 webview,虽然好用,但是在Fragment中传递消息困难,想要返回上一页,还得各种消息传递什么的,麻烦.可是在Fragment中又不能使用onKeyDown ...

  9. javascript解决在safari浏览器中使用history.back()返回上一页后页面不会刷新的问题

    我们知道,在JavaScript中提供了一个window.history.back()方法用于返回上一页,另外也可以使用window.history.go(-1)返回上一页(跳转). 在其他的主流浏览 ...

随机推荐

  1. Linux(centOS7)系统搭建Java环境变量

    [mikecheng@localhost ~]$ su[root@localhost usr]# mkdir tomcat[root@localhost usr]# mkdir java[root@l ...

  2. atcoder/CODE FESTIVAL 2017 qual B/B(dfs染色判断是否为二分图)

    题目链接:http://code-festival-2017-qualb.contest.atcoder.jp/tasks/code_festival_2017_qualb_c 题意:给出一个含 n ...

  3. docker与虚拟机性能比较(转)

    http://blog.csdn.net/cbl709/article/details/43955687 本博客来源于我的个人博客: www.chenbiaolong.com 欢迎访问. 概要 doc ...

  4. Mysql安装(Mac)

    1.安装mysql(百度详解) 2.打开终端 3.输入vim ~/.bash_profile 4.在最后加上PATH=$PATH:/usr/local/mysql/bin 5.按esc,然后输入 :w ...

  5. UVA11270 Tiling Dominoes

    \(\color{#0066ff}{ 题目描述 }\) 给定一个m×n的矩形网格,用1×2多米诺骨牌完全平铺. 请注意,即使一个平铺的旋转与另一个平铺相匹配,它们仍算作不同的平铺. 下面显示了一个平铺 ...

  6. log4j配置文件及java调用 每个级别输出到不同的文件

    #配置根Logger log4j.rootLogger = DEBUG , RollingFile,CONSOLE #文件大小达到一定尺寸的时候创建一个新的文件 log4j.appender.Roll ...

  7. tomcat 修改根路径

    修改setting.xml 在 </Host> 正上面 添加 <Context path="/" docBase="/TomExam" deb ...

  8. C语言中的定义与声明

    什么是定义?什么是声明?它们有何区别? 举个例子: 1 2 A)int i; B)extern int i;(关于extern,后面解释) 哪个是定义?哪个是声明?或者都是定义或者都是声明?我所教过的 ...

  9. 在Ubuntu中使用AppImage类型文件

    右键--属性---权限---允许作为执行文件启动

  10. 阿里Java开发规约(2)

    本文是对阿里插件中规约的详细解释二,关于插件使用,请参考这里 及时清理不再使用的代码段或配置信息. 说明:对于垃圾代码或过时配置,坚决清理干净,避免程序过度臃肿,代码冗余 Positive examp ...