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é)右核,請(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í)間的偏移量

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
  • 序言:七十年代末镰烧,一起剝皮案震驚了整個(gè)濱河市,隨后出現(xiàn)的幾起案子楞陷,更是在濱河造成了極大的恐慌怔鳖,老刑警劉巖,帶你破解...
    沈念sama閱讀 216,372評(píng)論 6 498
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件固蛾,死亡現(xiàn)場(chǎng)離奇詭異结执,居然都是意外死亡度陆,警方通過查閱死者的電腦和手機(jī),發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 92,368評(píng)論 3 392
  • 文/潘曉璐 我一進(jìn)店門献幔,熙熙樓的掌柜王于貴愁眉苦臉地迎上來懂傀,“玉大人,你說我怎么就攤上這事蜡感〉乓希” “怎么了?”我有些...
    開封第一講書人閱讀 162,415評(píng)論 0 353
  • 文/不壞的土叔 我叫張陵郑兴,是天一觀的道長(zhǎng)犀斋。 經(jīng)常有香客問我,道長(zhǎng)情连,這世上最難降的妖魔是什么叽粹? 我笑而不...
    開封第一講書人閱讀 58,157評(píng)論 1 292
  • 正文 為了忘掉前任,我火速辦了婚禮蒙具,結(jié)果婚禮上球榆,老公的妹妹穿的比我還像新娘。我一直安慰自己禁筏,他們只是感情好持钉,可當(dāng)我...
    茶點(diǎn)故事閱讀 67,171評(píng)論 6 388
  • 文/花漫 我一把揭開白布。 她就那樣靜靜地躺著篱昔,像睡著了一般每强。 火紅的嫁衣襯著肌膚如雪。 梳的紋絲不亂的頭發(fā)上州刽,一...
    開封第一講書人閱讀 51,125評(píng)論 1 297
  • 那天空执,我揣著相機(jī)與錄音,去河邊找鬼穗椅。 笑死辨绊,一個(gè)胖子當(dāng)著我的面吹牛,可吹牛的內(nèi)容都是我干的匹表。 我是一名探鬼主播门坷,決...
    沈念sama閱讀 40,028評(píng)論 3 417
  • 文/蒼蘭香墨 我猛地睜開眼,長(zhǎng)吁一口氣:“原來是場(chǎng)噩夢(mèng)啊……” “哼袍镀!你這毒婦竟也來了默蚌?” 一聲冷哼從身側(cè)響起,我...
    開封第一講書人閱讀 38,887評(píng)論 0 274
  • 序言:老撾萬(wàn)榮一對(duì)情侶失蹤苇羡,失蹤者是張志新(化名)和其女友劉穎绸吸,沒想到半個(gè)月后,有當(dāng)?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體,經(jīng)...
    沈念sama閱讀 45,310評(píng)論 1 310
  • 正文 獨(dú)居荒郊野嶺守林人離奇死亡锦茁,尸身上長(zhǎng)有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點(diǎn)故事閱讀 37,533評(píng)論 2 332
  • 正文 我和宋清朗相戀三年攘轩,在試婚紗的時(shí)候發(fā)現(xiàn)自己被綠了。 大學(xué)時(shí)的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片蜻势。...
    茶點(diǎn)故事閱讀 39,690評(píng)論 1 348
  • 序言:一個(gè)原本活蹦亂跳的男人離奇死亡撑刺,死狀恐怖,靈堂內(nèi)的尸體忽然破棺而出握玛,到底是詐尸還是另有隱情够傍,我是刑警寧澤,帶...
    沈念sama閱讀 35,411評(píng)論 5 343
  • 正文 年R本政府宣布挠铲,位于F島的核電站冕屯,受9級(jí)特大地震影響,放射性物質(zhì)發(fā)生泄漏拂苹。R本人自食惡果不足惜安聘,卻給世界環(huán)境...
    茶點(diǎn)故事閱讀 41,004評(píng)論 3 325
  • 文/蒙蒙 一、第九天 我趴在偏房一處隱蔽的房頂上張望瓢棒。 院中可真熱鬧浴韭,春花似錦、人聲如沸脯宿。這莊子的主人今日做“春日...
    開封第一講書人閱讀 31,659評(píng)論 0 22
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽(yáng)连霉。三九已至榴芳,卻和暖如春,著一層夾襖步出監(jiān)牢的瞬間跺撼,已是汗流浹背窟感。 一陣腳步聲響...
    開封第一講書人閱讀 32,812評(píng)論 1 268
  • 我被黑心中介騙來泰國(guó)打工, 沒想到剛下飛機(jī)就差點(diǎn)兒被人妖公主榨干…… 1. 我叫王不留歉井,地道東北人柿祈。 一個(gè)月前我還...
    沈念sama閱讀 47,693評(píng)論 2 368
  • 正文 我出身青樓,卻偏偏與公主長(zhǎng)得像哩至,于是被迫代替她去往敵國(guó)和親躏嚎。 傳聞我的和親對(duì)象是個(gè)殘疾皇子,可洞房花燭夜當(dāng)晚...
    茶點(diǎn)故事閱讀 44,577評(píng)論 2 353

推薦閱讀更多精彩內(nèi)容

  • 大家有片段開頭這種經(jīng)歷嗎憨募?自我介紹中對(duì)于愛好的介紹紧索,大家是不是經(jīng)常都是只是介紹了興趣事件袁辈,但并沒有介紹每個(gè)興趣事件...
    小太陽(yáng)and小煤球閱讀 140評(píng)論 0 0
  • 夕顏菜谣,正名月光花。 我常常分不清它和牽牛花尾膊,在我看來它們就像是一家人媳危。 了解它是因?yàn)樗幕ㄕZ(yǔ):生命中永不丟失的溫暖...
    橙星辰閱讀 501評(píng)論 0 3
  • 擁有“對(duì)子王”稱號(hào)的他今年五十歲左右,一般人見了他都會(huì)估計(jì)年齡為四十歲出頭冈敛。 一張被歲月優(yōu)待的臉待笑,神態(tài)帶著靦腆,笑...
    落雨初晴閱讀 978評(píng)論 2 2
  • 原來抓谴,請(qǐng)人吃素暮蹂,并不是為了讓自己積累功德或怎樣。 而是癌压,幫助自己召回失落已久的善良仰泻,熱忱,正直和誠(chéng)信滩届。 那顆善良有...
    lolipop很慢閱讀 174評(píng)論 0 0
  • 小時(shí)候我問姐姐什么是傻逼帜消。 姐姐說:“張嘴我靠閉嘴我操棠枉,一言不合日你媽的人就是傻逼∨萃Γ” 我又問姐姐什么是二逼辈讶。 姐...
    張?jiān)掳雐閱讀 8,323評(píng)論 169 317