標籤:ios 庫 github 下拉-重新整理
原創Blog,轉載請註明出處
blog.csdn.net/hello_hwc
我的Github
https://github.com/wenchenhuang/WCPullRefreshControl
前言:
寫IOS代碼有段時間了,是時候寫幾個Github的庫了,即鍛煉了自己,又能夠協助需要的人。
這個庫是一個下拉重新整理庫,自己用了10個小時左右的時間開發的,做了螢幕適配,旋轉適配,自己設計了一些動畫,API設計改了3次。最後,第一個版本提交到Github了。
地址
幾種
特點:
- 適配各種尺寸的螢幕
- 適配各種Scrollview(UIScrollview,UITableview,UIWebview)
- 支援裝置旋轉
- 支援最多12種下拉重新整理的混合(3種progress,4種refreshing,3*4=12)
- 支援Block和Delegate兩種方式傳遞事件
- 支援有導覽列的Scrollview
使用起來很簡單
- 把Classes檔案件拷拖拽到工程裡
- 在需要的地方 #import “WCSimplePullRefreshControl.h”,並且實現UIScrollViewDelegate
- 儲存一個WCSimplePullRefreshControl屬性
- 初始化,如果使用代理傳遞事件,則設定delegate為self
- 在scrollViewDidEndDragging裡調用updateWHenScrollDidEndDraging;在scrollViewDidScroll調用scrollViewDidScroll
- 在重新整理結束的時候,調用finishRefreshingSuccessully:
例子一 用Block傳遞事件
這裡使用預設的樣式
@interface DemoTableview()<UIScrollViewDelegate>@property (strong,nonatomic)WCSimplePullRefreshControl * pullRefresh;@end@implementation DemoTableview-(void)viewDidLoad{ self.pullRefresh = [[WCSimplePullRefreshControl alloc] initWithScrollview:self.tableView Action:^{ [self performSelector:@selector(reset) withObject:nil afterDelay:2.0]; }];}-(void)reset{ [self.pullRefresh finishRefreshingSuccessully:YES];}-(void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate{ [self.pullRefresh updateWHenScrollDidEndDraging];}-(void)scrollViewDidScroll:(UIScrollView *)scrollView{ [self.pullRefresh updateWhenScrollviewScroll];}
方式二 用代理傳遞事件
定製化樣式
@interface DemoTableview()<UIScrollViewDelegate,WCPullRefreshControlDelegate>@property (strong,nonatomic)WCSimplePullRefreshControl * pullRefresh;@end@implementation DemoTableview-(void)viewDidLoad{ self.pullRefresh = [[WCSimplePullRefreshControl alloc] initWithScrollview:self.tableView Action:NULL progressItem:WCProgressItemTypeMagicSquare refreshingItem:WCRefreshingItemTypeMagicSquare lastUpdate:nil showLastUpdate:NO textColor:[UIColor blueColor] itemColor:[UIColor grayColor] pullHeight:64];self.pullRefresh.delegate = self;}-(void)reset{ [self.pullRefresh finishRefreshingSuccessully:YES];}-(void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate{ [self.pullRefresh updateWHenScrollDidEndDraging];}-(void)scrollViewDidScroll:(UIScrollView *)scrollView{ [self.pullRefresh updateWhenScrollviewScroll];}-(void)DidStartRefreshingWithScrollview:(UIScrollView *)scrollview{ [self performSelector:@selector(reset) withObject:nil afterDelay:2.0];}@end
後續
如果發現bug,請在本部落格留言,或者email: [email protected]
開發IOS庫之下拉重新整理-WCPullRefreshControl