自定义下拉刷新控件-CBStoreHouseRefreshControl
本文转载至 http://www.cocoachina.com/ios/20141110/10177.html
iOS开发自定义刷新CBStoreHouseRefres
这是一款在Storehouse启发下创作出来的控件,下拉刷新的时候可以完全定制自己想要的效果。来看效果图:

通过plist文件你可以使用任何想要的形状,下面这张是作者所在公司的logo:

安装
CBStoreHouseRefreshControl依赖于CocoaPods,通过在你的Podfile中添加下面这行命令来安装:
|
1
|
pod "CBStoreHouseRefreshControl" |
当然你也可以直接把CBStoreHouseRefreshControl (.h .m) 和 BarItem (.h .m)文件直接拖到你的工程中去。
用法
只需要简单的使用下面这个方法你就可以将其添加到你的UIScrollView中,像使用UITableView和UICollectionView那样:
|
1
2
3
4
5
|
+ (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"]; |
还可以设定更多的参数:
|
1
2
3
4
5
6
7
8
9
10
11
12
|
+ (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,假如实现过就不必了。然后在刷新控件里传递调用。
|
1
2
3
4
5
6
7
8
|
- (void)scrollViewDidScroll:(UIScrollView *)scrollView{ [self.storeHouseRefreshControl scrollViewDidScroll];}- (void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate{ [self.storeHouseRefreshControl scrollViewDidEndDragging];} |
最后,确保你已经实现了之前用来监听刷新触发器的refreshAction。
|
1
2
3
4
5
6
|
- (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一同消失或者出现。
自定义下拉刷新控件-CBStoreHouseRefreshControl的更多相关文章
- 基于PtrFrameLayout实现自定义仿京东下拉刷新控件
前言 最近基于项目需要,使用PtrFrameLayout框架实现了自定义的下拉刷新控件,大体效果类似于京东APP的下拉刷新动态效果.在这里和大家分享一下具体的思路和需要注意的地方,以便帮助有类似开发和 ...
- android官方下拉刷新控件SwipeRefreshLayout的使用
可能开发安卓的人大多数都用过很多下拉刷新的开源组件,但是今天用了官方v4支持包的SwipeRefreshLayout觉得效果也蛮不错的,特拿出来分享. 简介:SwipeRefreshLayout组件只 ...
- [Android]下拉刷新控件RefreshableView的实现
以下内容为原创,欢迎转载,转载请注明 来自天天博客:http://www.cnblogs.com/tiantianbyconan/p/4172483.html 需求:自定义一个ViewGroup,实现 ...
- Android仿苹果版QQ下拉刷新实现(一) ——打造简单平滑的通用下拉刷新控件
前言: 忙完了结婚乐APP的开发,终于可以花一定的时间放在博客上了.好了,废话不多说,今天我们要带来的效果是苹果版本的QQ下拉刷新.首先看一下目标效果以及demo效果: 因为此效果实现的步骤 ...
- Android下拉刷新控件--PullToRefresh的简单使用
Android中很多时候都会用到上下拉刷新,这是一个很常用的功能,Android的v4包中也为我们提供了一种原生的下拉刷新控件--SwipeRefreshLayout,可以用它实现一个简洁的刷新效果, ...
- Android 解决下拉刷新控件和ScrollVIew的滑动冲突问题。
最近项目要实现ScrollView中嵌套广告轮播图+RecyleView卡片布局,并且RecyleView按照header和内容的排列样式,因为RecyleView的可扩展性很强,所以我毫无疑问的选择 ...
- Android——谷歌官方下拉刷新控件SwipeRefreshLayout(转)
转自:http://blog.csdn.net/zouzhigang96/article/details/50476402 版权声明:本文为博主原创文章,未经博主允许不得转载. 前言: 如今谷歌推出了 ...
- android SwipeRefreshLayout google官方下拉刷新控件
下拉刷新功能之前一直使用的是XlistView很方便我前面的博客有介绍 SwipeRefreshLayout是google官方推出的下拉刷新控件使用方法也比较简单 今天就来使用下SwipeRefres ...
- Android PullToRefresh下拉刷新控件的简单使用
PullToRefresh这个开源库早就听说了,不过一直没用过.作为一个经典的的开源库,我觉得还是有必要认识一下. 打开github上的网址:https://github.com/chrisbanes ...
随机推荐
- C# 的 String.CompareTo Equals和==的比较
String.CompareTo 语法 public int CompareTo( string strB) 返回值 小于 0,实例小于参数 strB: 0,实例等于参数 strB: 大于 0, ...
- Java发送邮件----自己封装的方法
发送邮件的封装类: package com.email; import java.util.Properties; import javax.mail.Authenticator; import ja ...
- 属性动画详解一(Property Animation)
效果图: Android动画有3类: 1.View Animation (Tween Animation) 2.Drawable Animation (Frame Animation) 2.Prope ...
- 八、Ubuntu安装Tomcat和jdk
1.解压Tomcat 和 jdk tar -zxvf apache-tomcat-8.0.28.tar.gz tar -zxvf jdk-8u60-linux-x64.gz 2.将解压后的tomcat ...
- asp.net mvc 自定义模型绑定
在asp.net mvc的控制器中如果能够活用模型的自动绑定功能的话能够减少许多工作量.但是如果我们想要对前台传来的数据进行一些处理再绑定到模型上,该怎么做呢? 这里用一个绑定用户数据的小案例来讲解a ...
- spring-cloud集成mybatis-plus
mybatis-plus插件是对mybatis做出系列增强插件,后面简称MP,MP可免去开发者重复编写xml.mapper.service.entity等代码,通过MP提供的实体注解来完成单表的CRU ...
- iOS 给三方日历加上农历
首先创建一个农历文件 LunarCalendar.h // // LunarCalendar.h // Hnair4iPhone // // Created by yingkong1987 on 13 ...
- Mac outlook设置自动回复
outlook是公司必不可少的软件, 在mac下开发,当然用的是mac版的outlook,今天介绍一下如何设置mac下outlook的自动回复. 有两种方式的帐号,一种是Exchange accoun ...
- 最长递增子序列问题—LIS
问题:给定一组数 a0,a0,....,an-1. 求该序列的最长递增(递减)序列的长度. 最长递增子序列长度的求法有O(n^2)和O(nlogn)两种算法. 1.复杂度为O(n^2)的算法. 设L[ ...
- python 浮点数保留小数
http://www.cnblogs.com/Raymon-Geng/p/5784290.html 这里有三种方法, round(a,2) '%.2f' % a Decimal('5.000').qu ...