CBStoreHouseRefreshControl支持 CocoaPods, 添加以下一行代碼到Podfile中即可:
pod "CBStoreHouseRefreshControl"
Alternatively, you can just drag CBStoreHouseRefreshControl (.h .m) and BarItem (.h .m) into your own project.
另一種方式就是:你把 CBStoreHouseRefreshControl (.h .m) 和 BarItem (.h .m) 文件拖到你的項(xiàng)目中就可以了。
How to use it
You can attach it to any UIScrollView like UITableView or UICollectionView using following simple static method:
你可以將它添加到UIScrollView的任何子類當(dāng)中玛瘸,用如下的一個(gè)方法:
+ (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"];
Or, using this method for more configurable options:
或者用下面的一個(gè)方法進(jìn)行更多的設(shè)置:
+ (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];
Then, implement UIScrollViewDelegate in your UIViewController if you haven't already, and pass the calls through to the refresh control:
然后蜕青,在你的控制器中實(shí)現(xiàn)你的UIScrollViewDelegate的一些方法,你將那些代理方法的值傳進(jìn)去即可:
- (void)scrollViewDidScroll:(UIScrollView *)scrollView
{
[self.storeHouseRefreshControl scrollViewDidScroll];
}
- (void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate
{
[self.storeHouseRefreshControl scrollViewDidEndDragging];
}
Lastly, make sure you've implemented the refreshAction you passed it earlier to listen for refresh triggers:
最后糊渊,確保你實(shí)現(xiàn)了刷新的操作:
- (void)refreshTriggered
{
//call your loading method here
//Finshed loading the data, reset the refresh control
[self.storeHouseRefreshControl finishingLoading];
}
For more details, please check out the demo app's code.
更多細(xì)節(jié)右核,請(qǐng)查閱示例代碼。
How to use your own shape
The CBStoreHouseRefreshControl's shape contains bunch of BarItem for animation, each BarItemis running its own animation, you need to provide startPoint and endPoint through a plist file.
All BarItem will share one coordinate system whose origin is at the top-left corner. For example if you want to draw a square, the plist will look like this:
CBStoreHouseRefreshControl的形狀包含了一系列的BarItem用于動(dòng)畫渺绒,每一個(gè)BarItem都執(zhí)行他自身的動(dòng)畫贺喝,你需要給他們?cè)趐list文件里面提供一個(gè)起始值和結(jié)束值。
所有的BarItem會(huì)分享同一個(gè)坐標(biāo)系統(tǒng)宗兼,這個(gè)坐標(biāo)系統(tǒng)的原始頂點(diǎn)在左上角躏鱼。如果你是要繪制一個(gè)正方形,那么针炉,plist文件中就應(yīng)該是如下的樣子。
Notes:
Make sure you put the right key which are startPoints and endPoints. 確保你的key值是在正確的起始點(diǎn)與結(jié)束點(diǎn)那里
Make sure you are using the right format ({x,y}) for coordinates. 確保你是使用了正確的坐標(biāo)系統(tǒng)
The highlight/loading animation will highlight each bar item in the same order you declare them in plist, use reverseLoadingAnimation to reverse the animation. 這個(gè)高亮效果會(huì)根據(jù)你的plist文件中列表的順序而依次高亮扳抽,你可以使用reverseLoadingAnimation來反轉(zhuǎn)動(dòng)畫效果
Easy way to generate startPoint and endPoint?
@isaced mentions that it's easier to use PaintCode to generate startPoint and endPoint:
你可以使用PaintCode來生成起始點(diǎn)與結(jié)束點(diǎn)
Configuration
Play with following parameters to configure CBStoreHouseRefreshControl's view and animation:
你可以根據(jù)如下的一些參數(shù)來配置CBStoreHouseRefreshControl的動(dòng)畫效果:
Set the bar color with the color parameter 設(shè)置bar的顏色
Set the bar width with the lineWidth parameter 設(shè)置bar的寬度以及線寬
Set the height of control with the dropHeight parameter 設(shè)置控制器的垂直高度篡帕??贸呢?
Set the scale of control with the scale parameter 設(shè)置縮放參數(shù)
Adjust how disperse the bar items appear/disappear by changing the horizontalRandomnessparameter 調(diào)整bar是怎么消失的
Set if reversing the loading animation with the reverseLoadingAnimation parameter, if set to YES, the last bar item will be highlighted firstly. 反轉(zhuǎn)動(dòng)畫的順序
Adjust the time offset of the appear/disappear animation by changing theinternalAnimationFactor parameter, for example if internalAnimationFactor is 1 all bar items will appear/disappear all together. 調(diào)整動(dòng)畫時(shí)間的偏移量