国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學院 > 開發設計 > 正文

在UITableView中識別左右滑動,實現上下翻頁的功能

2019-11-14 20:26:57
字體:
來源:轉載
供稿:網友

目前有三種方案:

1.

UIScrollView + UITableView。

實現方法,在UIScrollView中,加入UITableView即可

設置UIScrollView的代理和方法

- (void)scrollViewDidScroll:(UIScrollView *)scrollView{    int currentPostion = scrollView.contentOffset.x;    if (currentPostion - 0 > 50) {        NSLog(@"Scroll right now ");    }    else if (0 - currentPostion > 50)    {        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");}

 


發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 定远县| 博野县| 江口县| 惠水县| 奉化市| 西昌市| 泸州市| 屏山县| 名山县| 多伦县| 龙陵县| 宁化县| 稻城县| 无极县| 沈丘县| 阳西县| 工布江达县| 陇川县| 平阴县| 聂荣县| 曲靖市| 临猗县| 秦皇岛市| 建昌县| 时尚| 兴义市| 杭锦后旗| 定远县| 达日县| 庐江县| 布尔津县| 泸溪县| 呈贡县| 玉林市| 海原县| 台北市| 浏阳市| 兰溪市| 根河市| 阳朔县| 乐亭县|