CBStoreHouseRefreshControl實(shí)現(xiàn)自定義下拉刷新

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é),請查閱示例代碼。

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用于動畫,每一個(gè)BarItem都執(zhí)行他自身的動畫,你需要給他們在plist文件里面提供一個(gè)起始值和結(jié)束值。

所有的BarItem會分享同一個(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è)高亮效果會根據(jù)你的plist文件中列表的順序而依次高亮,你可以使用reverseLoadingAnimation來反轉(zhuǎn)動畫效果


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的動畫效果:

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)動畫的順序

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)整動畫時(shí)間的偏移量

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

  • 大家有片段開頭這種經(jīng)歷嗎?自我介紹中對于愛好的介紹,大家是不是經(jīng)常都是只是介紹了興趣事件,但并沒有介紹每個(gè)興趣事件...
    小太陽and小煤球閱讀 172評論 0 0
  • 夕顏,正名月光花。 我常常分不清它和牽?;ǎ谖铱磥硭鼈兙拖袷且患胰?。 了解它是因?yàn)樗幕ㄕZ:生命中永不丟失的溫暖...
    橙星辰閱讀 603評論 0 3
  • 擁有“對子王”稱號的他今年五十歲左右,一般人見了他都會估計(jì)年齡為四十歲出頭。 一張被歲月優(yōu)待的臉,神態(tài)帶著靦腆,笑...
    落雨初晴閱讀 1,083評論 2 2
  • 原來,請人吃素,并不是為了讓自己積累功德或怎樣。 而是,幫助自己召回失落已久的善良,熱忱,正直和誠信。 那顆善良有...
    lolipop很慢閱讀 200評論 0 0
  • 小時(shí)候我問姐姐什么是傻逼。 姐姐說:“張嘴我靠閉嘴我操,一言不合日你媽的人就是傻逼?!?我又問姐姐什么是二逼。 姐...
    張?jiān)掳雐閱讀 8,428評論 169 317

友情鏈接更多精彩內(nèi)容