在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)返回上一页(跳转). 在其他的主流浏览 ...
随机推荐
- (原创)团体程序设计天梯赛-练习集 L1-048 矩阵A乘以B (15 分)
给定两个矩阵A和B,要求你计算它们的乘积矩阵AB.需要注意的是,只有规模匹配的矩阵才可以相乘.即若A有Ra行.Ca列,B有Rb行.Cb列,则只有Ca与Rb相等时,两 ...
- Javascript之入门篇(一)
上一篇学习了什么是JavaScript语言及其作用和特有的特点等,本篇将详细介绍JavaScript一些入门使用方式. 对于初学者来讲,由于JavaScript是嵌入到HTML页面里面的,首先创建一张 ...
- kuangbin专题16D(next求最小循环节)
题目链接: https://vjudge.net/contest/70325#problem/D 题意: 给出一个循环字符串, 可以在两端添加任意字符, 问最少添加多少字符可以使循环字符串变成周期循环 ...
- python内置函数print输出到文件,实现日志记录的功能
# bulid time 2018-6-22 import os import time def log(*args, **kwargs): # *kargs 为了通用 可不传 rule = &quo ...
- AP_MergeSql
) FROM DELTA.PRMCN WHERE ETL_FLAG IN ('A','D')) S; --重跑:删除已跑入数据 DELETE FROM CCRD.PRMCN WHERE JOB_SEQ ...
- javascript事件委托//就是父级事件给子级
<!DOCTYPE html><html><head> <title></title> <style type="text/ ...
- 数据结构19: BF算法(普通模式匹配算法)
判断两个串之间是否存在主串与子串的关系,这个过程称为串的模式匹配. 在串的模式匹配过程,子串 T 通常被叫做“模式串”. 普通的模式匹配(“BF”算法) 判断两个串是否存在子串与主串的关系,最直接的算 ...
- 昂达v981平板刷机教程连接
http://tieba.baidu.com/p/3721193574 http://www.ondabbs.cn/forum.php?mod=viewthread&tid=65393 htt ...
- Python字符串拼接、格式化输出、深浅复制
1.Python字符串拼接:方法挺多.挺好用的.灵活使用可使代码简洁.可读性好. #1.用4种方法,将列表li = ['I','python','like'], #里面的单词拼成: I**like** ...
- Apache 在 htaccess 禁止访问 和 conf 中的 禁止访问 区别
相信熟悉Web Server的人一定熟悉Apahce.相信熟悉Apahce的人一定知道URL Rewrite.Apache的mod_rewrite模块,可以帮助人们构造出各种各样美化后的URL.在Ap ...