码迷,mamicode.com
首页 > 移动开发 > 详细

开发IOS库之下拉刷新-WCPullRefreshControl

时间:2015-04-15 17:07:42      阅读:137      评论:0      收藏:0      [点我收藏+]

标签: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: njuhwc@163.com

开发IOS库之下拉刷新-WCPullRefreshControl

标签:ios      github   下拉-刷新   

原文地址:http://blog.csdn.net/hello_hwc/article/details/45060885

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!