目前有三种方案:

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. D. Minimum Diameter Tree 思维+猜结论

    D. Minimum Diameter Tree 思维+猜结论 题意 给出一颗树 和一个值v 把该值任意分配到任意边上 使得\(\sum\limits_{i,j}p_{ij}=v\) 使得 这颗树任意 ...

  2. ubuntu14.04 apt-get install找不到软件,更换源解决

    安装14.04后,有时使用apt-get命令安装程序,会提示找不到程序,这是因为软件源不正确,网上说的换163的.中科大的.阿里的等等,我在更新源的时候都会出错,一般是报404错误,网上也没找到好的办 ...

  3. Vscode 配置 maven debug

    # maven.cmd 上方设置此变量 set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address= ...

  4. JavaScript权威指南--闭包讲解摘记

    不积跬步无以至千里,不积小流无以成江河. 关于闭包的解释,在<JavaScript权威指南>中讲的很透彻了.今天看了书中的一个段讲解,更加深了对闭包的理解,特此记下,以备查阅. 在同一个作 ...

  5. jq自定义鼠标右键菜单

    效果: 代码: <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <t ...

  6. BeautifulSoup4模块的使用

    1. 安装 pip3 install beautifulsoup42. 使用 from bs4 import BeautifulSoup obj = BeautifulSoup("HTML内 ...

  7. Go语言基础之10--面向对象编程2之方法

    一.方法的定义 之前我们学习了结构体(struct),其仅仅是对数据的封装,并没有行为方法,还不是一个完全的面向对象的思路,所以现在我们来学习在结构体的基础上如何去定义一个方法.结构体(类)+方法=完 ...

  8. Go语言基础练习题系列1

    1.练习1 题目:使用fmt分别打印字符串.二进制.十进制.十六进制.浮点数. package main import ( "fmt" ) func main() { var a ...

  9. css3 box-shadow 用法

    第1个值水平偏移值 第2个值垂直偏移值 第3个值设置对象的阴影模糊值 第4个值设置对象的阴影外延值 外阴影常规效果box-shadow:5px 5px rgba(0,0,0,.6); 外阴影模糊效果b ...

  10. mybatis主键是在insert前生成还是之后生成

    oracle sequence 推荐每个表使用自己的sequence mysql 使用每个表的autoincreate来当主键 mybatis 操作insert时 主键的生成是在插入之前 还是之后? ...