首页 > 移动平台 > 详细

开发IOS库之下拉刷新-WCPullRefreshControl

时间:2015-04-15 17:06:25      阅读:294      评论:0      收藏:0      [点我收藏+]

原创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

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

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!