在UITableView中识别左右滑动,实现上下翻页的功能
目前有三种方案:
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
@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中识别左右滑动,实现上下翻页的功能的更多相关文章
- js中的referrer使用,返回上一页
js完整代码: <script language="javascript"> var refer=document. referrer ; document.g ...
- linux中使sqlplus能够上下翻页
安装包链接:https://pan.baidu.com/s/1WsQTeEQClM88aEqIvNi2ag 提取码:s241 rlwrap-0.37-1.el6.x86_64.rpm 和 rlwra ...
- linux vi编辑器中,如何通过快捷键上下翻页?
需求说明: 之前在vi的时候,如果想看下一页,就直接按住 ↓ 这个箭头一直翻,现在觉得有些麻烦, 就找了下上,下翻页的快捷方式.在此记录下. 记录: 1.向下翻页快捷键(下一页):Ctrl + f 2 ...
- php实现返回上一页的功能
php实现返回上一页的功能的3种有效方法 header(location:你的上一页的路径); // 注意这个函数前不能有输出 header(location:.getenv(&qu ...
- 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 ...
- php实现返回上一页的功能的3种有效方法
php实现返回上一页的功能的3种有效方法 header(location:你的上一页的路径); // 注意这个函数前不能有输出 header(location:.getenv("HT ...
- 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 ...
- android studio中Fragment使用webview返回上一页的问题
在Fragment中使用了腾讯的X5 webview,虽然好用,但是在Fragment中传递消息困难,想要返回上一页,还得各种消息传递什么的,麻烦.可是在Fragment中又不能使用onKeyDown ...
- javascript解决在safari浏览器中使用history.back()返回上一页后页面不会刷新的问题
我们知道,在JavaScript中提供了一个window.history.back()方法用于返回上一页,另外也可以使用window.history.go(-1)返回上一页(跳转). 在其他的主流浏览 ...
随机推荐
- Oracle PL/SQL编程语法
--plsql块结构,计算a,b的和 declare a ; b ; c int; begin c:=a+b; dbms_output.put_line(c); end; --%type数据类型,输出 ...
- ASPxGridView 下拉框不让输入
DropDownStyle="DropDownList"该属性使combox控件不能手动输入数据,只能在下拉列表中选择
- django 基础框架学习 (二)
Django框架基础-02 Django缓存cookie 1.说明 当我们服务器在响应数据的同时,希望写⼊⼀些缓存数据到客户端 我们可以选择在响应的同时,将要写⼊到客户端的 ...
- git相关问题处理
1.在git push时无法提交代码,相对于git服务器上,本身代码可能不是最新的,因此提交的时候会报以下这个错误 Updates were rejected because the tip of y ...
- MySQL数据查询结果导出生成文件
select url from news where url like "%美女%" into outfile "/导出的文件路径" : 在这里有个坑,对于 ...
- MySQL使用总结
本篇博客,主要是对MySQL使用的一些总结,会持续更新. MySQL下载安装不再赘述.去官网即可.有企业版和社区版. 用命令行的方式: 1. 先运行MySQL目录的bin下的mysqld.exe ...
- 利用JPanel和JLabel设置背景图片
//创建面板1,放置背景图片1 JPanel jPanelTop=new JPanel(); jPanelTop.setBounds(,-,,); //x=0,y=-5用来设置面板距离窗体左上角的距离 ...
- [Leetcode]014. Longest Common Prefix
public class Solution { public String longestCommonPrefix(String[] strs) { if(strs == null || strs.l ...
- P5021 赛道修建 (NOIP2018)
传送门 考场上把暴力都打满了,结果文件输入输出写错了.... 当时时间很充裕,如果认真想想正解是可以想出来的.. 问你 长度最小的赛道长度的最大值 显然二分答案 考虑如何判断是否可行 显然对于一个节点 ...
- 华东交通大学2015年ACM“双基”程序设计竞赛1002
Problem B Time Limit : 3000/1000ms (Java/Other) Memory Limit : 65535/32768K (Java/Other) Total Sub ...