開發IOS庫之下拉重新整理-WCPullRefreshControl

來源:互聯網
上載者:User

標籤: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

使用起來很簡單

  1. 把Classes檔案件拷拖拽到工程裡
  2. 在需要的地方 #import “WCSimplePullRefreshControl.h”,並且實現UIScrollViewDelegate
  3. 儲存一個WCSimplePullRefreshControl屬性
  4. 初始化,如果使用代理傳遞事件,則設定delegate為self
  5. 在scrollViewDidEndDragging裡調用updateWHenScrollDidEndDraging;在scrollViewDidScroll調用scrollViewDidScroll
  6. 在重新整理結束的時候,調用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

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.