自定义下拉刷新控件-CBStoreHouseRefreshControl
来源:互联网 发布:化妆品成分知多少 编辑:程序博客网 时间:2024/05/02 02:03
介绍
这是一款在Storehouse启发下创作出来的控件,下拉刷新的时候可以完全定制自己想要的效果。来看效果图:
通过plist文件你可以使用任何想要的形状,下面这张是作者所在公司的logo:
安装
CBStoreHouseRefreshControl依赖于CocoaPods,通过在你的Podfile中添加下面这行命令来安装:
pod "CBStoreHouseRefreshControl"
当然你也可以直接把CBStoreHouseRefreshControl (.h .m) 和 BarItem (.h .m)文件直接拖到你的工程中去。
用法
只需要简单的使用下面这个方法你就可以将其添加到你的UIScrollView中,像使用UITableView和UICollectionView那样:
+ (CBStoreHouseRefreshControl*)attachToScrollView:(UIScrollView *)scrollView target:(id)target refreshAction:(SEL)refreshAction plist:(NSString *)plist;self.storeHouseRefreshControl = [CBStoreHouseRefreshControl attachToScrollView:self.tableView target:self refreshAction:@selector(refreshTriggered:) plist:@"storehouse"];
还可以设定更多的参数:
+ (CBStoreHouseRefreshControl*)attachToScrollView:(UIScrollView *)scrollView target:(id)target refreshAction:(SEL)refreshAction plist:(NSString *)plist color:(UIColor *)color lineWidth:(CGFloat)lineWidth dropHeight:(CGFloat)dropHeight scale:(CGFloat)scale horizontalRandomness:(CGFloat)horizontalRandomness reverseLoadingAnimation:(BOOL)reverseLoadingAnimation internalAnimationFactor:(CGFloat)internalAnimationFactor;self.storeHouseRefreshControl = [CBStoreHouseRefreshControl attachToScrollView:self.tableView target:self refreshAction:@selector(refreshTriggered:) plist:@"storehouse" color:[UIColor whiteColor] lineWidth:1.5 dropHeight:80 scale:1 horizontalRandomness:150 reverseLoadingAnimation:YES internalAnimationFactor:0.5];
接下来就是在你的UIViewController中实现UIScrollViewDelegate,假如实现过就不必了。然后在刷新控件里传递调用。
- (void)scrollViewDidScroll:(UIScrollView *)scrollView{ [self.storeHouseRefreshControl scrollViewDidScroll];}- (void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate{ [self.storeHouseRefreshControl scrollViewDidEndDragging];}
最后,确保你已经实现了之前用来监听刷新触发器的refreshAction。
- (void)refreshTriggered{ //call your loading method here //Finshed loading the data, reset the refresh control [self.storeHouseRefreshControl finishedLoading];}
想了解更多请看源码。
使用自定义图形
CBStoreHouseRefreshControl中的图形使用BarItem来实现动画,每个BarItem会有自己的动画,你仅需要使用plist文件为其指定开始点starPoint和结束点endPoint。
所有的BarItem共享的是以屏幕左上角为原点的坐标系,比如你要绘制一个正方形的话,plist文件就该这么写:
效果如下:
注意
确保为开始点startPoint和结束点endPoint都设置了正确的值。
确保坐标的书写是{x,y}的形式
使用loading或者是highlight的动画都会使得plist中所有BarItem按顺序高亮,而使用reverseLoadingAnimation则相反。
@isaced同学提到,使用PaintCode来生成开始点和结束点会更轻松得多,具体介绍看这里。
配置方法
color参数用于设置Baritem的颜色
lineWidth则可以设置Baritem的宽度
dropHeight用来设置控件的高度
scale可以设置控件比例
horizontalRandomness能改变Baritme的散开方式
reverseLoadAnimation设置为YES的话可以Baritem的高亮顺序会颠倒
internalAnimationFactor用于改变Baritem动画时间,如果设置为1,则所有Baritem一同消失或者出现。
(本文由CocoaChina翻译自GitHub,转载请注明出处。)
- 自定义下拉刷新控件-CBStoreHouseRefreshControl
- 自定义下拉刷新控件-CBStoreHouseRefreshControl
- 自定义下拉刷新控件-CBStoreHouseRefreshControl
- 自定义下拉刷新控件-CBStoreHouseRefreshControl
- 自定义下拉刷新控件-CBStoreHouseRefreshControl
- 自定义控件--下拉刷新
- 自定义控件-下拉刷新
- 自定义控件--下拉刷新
- 自定义下拉刷新控件
- 自定义控件:下拉刷新
- Android自定义控件下拉刷新
- 关于下拉刷新自定义控件
- 自定义下拉刷新控件-仿美团刷新效果
- Android PullToRefreshView自定义下拉刷新控件
- Android自定义控件之仿美团下拉刷新
- Android自定义控件之仿美团下拉刷新
- Android自定义控件--下拉刷新的实现
- 自定义控件 CustomListView (下拉刷新)
- jqmPhp – jQuery Mobile项目的HTML代码生成器
- js得到昨天的时间
- python 学习笔记 UDP
- 通配符&正则表达式
- 哪位知道基带怎么修复?
- 自定义下拉刷新控件-CBStoreHouseRefreshControl
- UVA 11729 Commando War(贪心)
- python 学习笔记 Email
- 2.4
- iOS基本数据类型-NSDictionary/NSMutableDictionary
- 方案公司内置apk怎么内置
- Python学习笔记 访问数据库
- 开发者眼中的PhoneGap体验
- UVA 714 Copying Books(最大值最小化)