目前有三种方案:

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. 【转】c# 读取excel数据的两种方法

    源地址:http://www.cnblogs.com/icyJ/p/ReadExcel.html

  2. [51nod1239] 欧拉函数之和(杜教筛)

    题面 传送门 题解 话说--就一个杜教筛--刚才那道拿过来改几行就行了-- //minamoto #include<bits/stdc++.h> #define R register #d ...

  3. CF1005F Berland and the Shortest Paths

    \(\color{#0066ff}{ 题目描述 }\) 一个无向图(边权为1),输出一下选边的方案使\(\sum d_i\)最小(\(d_i\)为从1到i的最短路) 输出一个方案数和方案(方案数超过k ...

  4. excle导出使用poi

    package com.ittax.core.util; import java.util.List; import javax.servlet.ServletOutputStream; import ...

  5. Qt 学习之路 2(8):添加动作

    Home / Qt 学习之路 2 / Qt 学习之路 2(8):添加动作       [在WINDOWS10 QTCREATOR MENU添加无效]   Qt 学习之路 2(8):添加动作  豆子   ...

  6. maven 打包 包含xml

    <build> <finalName>dc-exam</finalName> <!-- 包含xml文件 --> <resources> &l ...

  7. P4289 [HAOI2008]移动玩具

    传送门 广搜 4*4 的方阵只有 0 和 1 显然可以状态压缩 (如样例的开始状态压缩后就是1111000011100010) 为了加快速度用了双向广搜(顺便学了一下双向广搜) 双向广搜顾名思义 就是 ...

  8. Xsheel远程链接ECS,Xftp上传文件到ECS

    下载Xshell 工具:用来远程实现远程访问. 下载Xftp工具:方便用来上传文件. 下载方式直接百度搜索,如下如: 下载完成之后安装. 接下来就是链接云服务器了. 直接百度经验按照步骤来就OK了,如 ...

  9. java中所有开源注解收集

    @resource: resource全名为@Resource ,用来激活一个命名资源(namedresource)的依赖注入,在JavaEE应用程序中,该注解被典型地转换为绑定于JNDI conte ...

  10. 转 dango的模型总结 and django-关于manage.py migrate无效的问题

    http://iluoxuan.iteye.com/blog/1703061 1:用过django就知道django的model有多方便: 首先介绍下django的模型有哪些属性:先看例子: Djan ...