@@ -10,34 +10,86 @@ import Foundation
1010import UIKit
1111
1212enum RefreshResult {
13+ /**
14+ * 刷新成功
15+ */
1316 case Success
17+ /**
18+ * 刷新失败
19+ */
1420 case Failure
21+ /**
22+ * 刷新出错
23+ */
1524 case Error
25+ /**
26+ * 默认状态
27+ */
1628 case None
1729}
1830protocol RefreshAble : class {
31+ /**
32+ 触发动作的距离,对于header/footer来讲,就是视图的高度;对于left/right来讲,就是视图的宽度
33+ */
1934 func distanceToRefresh( ) -> CGFloat
35+ /**
36+ 已经开始执行刷新逻辑,在一次刷新中,只会调用一次
37+ */
2038 func didBeginRefreshing( )
2139}
2240protocol RefreshableHeader : RefreshAble {
41+ /**
42+ 拖拽的过程中,拖拽的百分比
43+
44+ - parameter percent: 拖拽的百分比,比如一共距离是100,那么拖拽10的时候,percent就是0.1
45+ */
2346 func percentageChangedDuringDragging( percent: CGFloat )
47+ /**
48+ 将要开始刷洗
49+ */
2450 func willBeginRefreshing( )
51+ /**
52+ 将要结束刷新,对应刷新的Header将要隐藏
53+
54+ - parameter result: 刷新结果
55+ */
2556 func willEndRefreshing( result: RefreshResult )
57+ /**
58+ 已经结束刷新,对应刷新的Header完全隐藏
59+
60+ - parameter result: 刷新结果
61+ */
2662 func didEndRefreshing( result: RefreshResult )
2763}
2864
2965protocol RefreshableFooter : RefreshAble {
66+ /**
67+ 不需要下拉加载更多的回调
68+ */
3069 func didUpdateToNoMoreData( )
70+ /**
71+ 重新设置到常态的回调
72+ */
3173 func didResetToDefault( )
74+ /**
75+ 结束刷新的回调
76+ */
3277 func didEndRefreshing( )
3378}
3479
3580protocol RefreshableLeftRight : RefreshAble {
81+ /**
82+ 结束刷新的回调
83+ */
3684 func didEndRefreshing( )
85+ /**
86+ 拖动百分比变化的回调
87+
88+ - parameter percent: 拖动百分比,大于0
89+ */
3790 func percentageChangedDuringDragging( percent: CGFloat )
3891}
3992
40- //Easy to setup
4193
4294public protocol SetUp { }
4395extension SetUp where Self: AnyObject {
@@ -85,6 +137,10 @@ extension UIScrollView{
85137//Footer
86138extension UIScrollView {
87139 func setUpFooterRefresh( action: ( ) -> ( ) ) -> DefaultRefreshFooter {
140+ let footer = DefaultRefreshFooter ( frame: CGRectMake ( 0 , 0 , CGRectGetWidth ( self . frame) , PullToRefreshKitConst . defaultFooterHeight) )
141+ return setUpFooterRefresh ( footer, action: action)
142+ }
143+ func setUpFooterRefresh< T: UIView where T: RefreshableFooter > ( footer: T , action: ( ) -> ( ) ) -> T {
88144 let oldContain = self . viewWithTag ( PullToRefreshKitConst . footerTag)
89145 oldContain? . removeFromSuperview ( )
90146 let frame = CGRectMake ( 0 , 0 , CGRectGetWidth ( self . frame) , PullToRefreshKitConst . defaultFooterHeight)
@@ -94,14 +150,11 @@ extension UIScrollView{
94150 containComponent. refreshAction = action
95151 self . insertSubview ( containComponent, atIndex: 0 )
96152
97- let footer = DefaultRefreshFooter ( frame: containComponent. bounds)
98153 containComponent. delegate = footer
99154 footer. autoresizingMask = [ . FlexibleWidth, . FlexibleHeight]
155+ footer. frame = containComponent. bounds
100156 containComponent. addSubview ( footer)
101157 return footer
102- }
103- func setUpFooterRefresh< T: UIView where T: RefreshableFooter > ( component: T , action: ( ) -> ( ) ) {
104-
105158 }
106159 func beginFooterRefreshing( ) {
107160 let footer = self . viewWithTag ( PullToRefreshKitConst . footerTag) as? RefreshHeaderContainer
@@ -129,6 +182,10 @@ extension UIScrollView{
129182//Left
130183extension UIScrollView {
131184 func setUpLeftRefresh( action: ( ) -> ( ) ) -> DefaultRefreshLeft {
185+ let left = DefaultRefreshLeft ( frame: CGRectMake ( 0 , 0 , PullToRefreshKitConst . defaultLeftWidth, CGRectGetHeight ( self . frame) ) )
186+ return setUpLeftRefresh ( left, action: action)
187+ }
188+ func setUpLeftRefresh< T: UIView where T: RefreshableLeftRight > ( left: T , action: ( ) -> ( ) ) -> T {
132189 let oldContain = self . viewWithTag ( PullToRefreshKitConst . leftTag)
133190 oldContain? . removeFromSuperview ( )
134191 let frame = CGRectMake ( - 1.0 * PullToRefreshKitConst. defaultLeftWidth, 0 , PullToRefreshKitConst . defaultLeftWidth, CGRectGetHeight ( self . frame) )
@@ -137,19 +194,20 @@ extension UIScrollView{
137194 containComponent. refreshAction = action
138195 self . insertSubview ( containComponent, atIndex: 0 )
139196
140- let left = DefaultRefreshLeft ( frame: containComponent. bounds)
141197 containComponent. delegate = left
142198 left. autoresizingMask = [ . FlexibleWidth, . FlexibleHeight]
199+ left. frame = containComponent. bounds
143200 containComponent. addSubview ( left)
144201 return left
145202 }
146- func setUpLeftRefresh< T: UIView where T: RefreshableLeftRight > ( component: T , action: ( ) -> ( ) ) {
147-
148- }
149203}
150204//Right
151205extension UIScrollView {
152206 func setUpRightRefresh( action: ( ) -> ( ) ) -> DefaultRefreshRight {
207+ let right = DefaultRefreshRight ( frame: CGRectMake ( 0 , 0 , PullToRefreshKitConst . defaultLeftWidth , CGRectGetHeight ( self . frame) ) )
208+ return setUpRightRefresh ( right, action: action)
209+ }
210+ func setUpRightRefresh< T: UIView where T: RefreshableLeftRight > ( right: T , action: ( ) -> ( ) ) -> T {
153211 let oldContain = self . viewWithTag ( PullToRefreshKitConst . rightTag)
154212 oldContain? . removeFromSuperview ( )
155213 let frame = CGRectMake ( 0 , 0 , PullToRefreshKitConst . defaultLeftWidth , CGRectGetHeight ( self . frame) )
@@ -158,13 +216,10 @@ extension UIScrollView{
158216 containComponent. refreshAction = action
159217 self . insertSubview ( containComponent, atIndex: 0 )
160218
161- let right = DefaultRefreshRight ( frame: containComponent. bounds)
162219 containComponent. delegate = right
163220 right. autoresizingMask = [ . FlexibleWidth, . FlexibleHeight]
221+ right. frame = containComponent. bounds
164222 containComponent. addSubview ( right)
165223 return right
166224 }
167- func setUpRightRefresh< T: UIView where T: RefreshableLeftRight > ( component: T , action: ( ) -> ( ) ) {
168-
169- }
170225}
0 commit comments