@@ -30,7 +30,7 @@ public class DefaultRefreshHeader:UIView,RefreshableHeader{
3030 addSubview ( spinner)
3131 addSubview ( textLabel)
3232 addSubview ( imageView) ;
33- let image = UIImage ( named: " arrow_down " , inBundle: NSBundle ( forClass: self . dynamicType ) , compatibleWithTraitCollection: nil )
33+ let image = UIImage ( named: " arrow_down " , inBundle: NSBundle ( forClass: DefaultRefreshHeader . self ) , compatibleWithTraitCollection: nil )
3434 imageView. image = image
3535 imageView. sizeToFit ( )
3636 imageView. frame = CGRectMake ( 0 , 0 , 24 , 24 )
@@ -60,7 +60,8 @@ public class DefaultRefreshHeader:UIView,RefreshableHeader{
6060 public func distanceToRefresh( ) -> CGFloat {
6161 return PullToRefreshKitConst . defaultHeaderHeight
6262 }
63- public func percentageChangedDuringDragging( percent: CGFloat ) {
63+ public func percentUpdateWhenNotRefreshing( percent: CGFloat ) {
64+
6465 self . hidden = !( percent > 0.0 )
6566 if percent > 1.0 {
6667 textLabel. text = textDic [ . releaseToRefresh]
@@ -81,7 +82,11 @@ public class DefaultRefreshHeader:UIView,RefreshableHeader{
8182 } )
8283 }
8384 }
84- public func willEndRefreshing( result: RefreshResult ) {
85+
86+ public func percentageChangedDuringReleaseing( percent: CGFloat ) {
87+
88+ }
89+ public func didBeginEndRefershingAnimation( result: RefreshResult ) {
8590 spinner. stopAnimating ( )
8691 imageView. transform = CGAffineTransformIdentity
8792 imageView. hidden = false
@@ -96,19 +101,16 @@ public class DefaultRefreshHeader:UIView,RefreshableHeader{
96101 textLabel. text = textDic [ . pullToRefresh]
97102 }
98103 }
99- public func didEndRefreshing ( result: RefreshResult ) {
104+ public func didCompleteEndRefershingAnimation ( result: RefreshResult ) {
100105 textLabel. text = textDic [ . pullToRefresh]
101106 self . hidden = true
102107 }
103- public func willBeginRefreshing ( ) {
108+ public func releaseWithRefreshingState ( ) {
104109 self . hidden = false
105110 textLabel. text = textDic [ . refreshing]
106111 spinner. startAnimating ( )
107112 imageView. hidden = true
108113 }
109- public func didBeginRefreshing( ) {
110-
111- }
112114}
113115
114116public class RefreshHeaderContainer : UIView {
@@ -147,7 +149,7 @@ public class RefreshHeaderContainer:UIView{
147149 self . attachedScrollView. contentInset = oldInset
148150
149151 } , completion: { ( finished) in
150- self . delegate? . didEndRefreshing ( self . currentResult)
152+ self . delegate? . didCompleteEndRefershingAnimation ( self . currentResult)
151153 } )
152154 case . Refreshing:
153155 dispatch_async ( dispatch_get_main_queue ( ) , {
@@ -158,9 +160,10 @@ public class RefreshHeaderContainer:UIView{
158160 self . attachedScrollView. contentInset = oldInset
159161 self . attachedScrollView. contentOffset = CGPointMake ( 0 , - 1.0 * top)
160162 } , completion: { ( finsihed) in
161- self . delegate? . didBeginRefreshing ( )
162163 self . refreshAction ? ( )
163164 } )
165+ self . delegate? . percentUpdateWhenNotRefreshing ( 1.0 )
166+ self . delegate? . releaseWithRefreshingState ( )
164167 } )
165168 default :
166169 break
@@ -210,7 +213,7 @@ public class RefreshHeaderContainer:UIView{
210213 }
211214 func handleScrollOffSetChange( change: [ String : AnyObject ] ? ) {
212215 if state == . Refreshing {
213- //Refre from here https://github.com/CoderMJLee/MJRefresh/blob/master/MJRefresh/Base/MJRefreshHeader.m, thanks to this lib again
216+ //Refer from here https://github.com/CoderMJLee/MJRefresh/blob/master/MJRefresh/Base/MJRefreshHeader.m, thanks to this lib again
214217 guard self . window != nil else {
215218 return
216219 }
@@ -231,16 +234,27 @@ public class RefreshHeaderContainer:UIView{
231234 return
232235 }
233236 let normal2pullingOffsetY = topShowOffsetY - self . frame. size. height
234- let percent = ( topShowOffsetY - offSetY) / self . frame. size. height
235237 if attachedScrollView. dragging {
236238 if state == . Idle && offSetY < normal2pullingOffsetY {
237239 self . state = . Pulling
238240 } else if state == . Pulling && offSetY >= normal2pullingOffsetY{
239241 state = . Idle
240242 }
241- self . delegate? . percentageChangedDuringDragging ( percent)
242243 } else if state == . Pulling{
243244 beginRefreshing ( )
245+ return
246+ }
247+ let percent = ( topShowOffsetY - offSetY) / self . frame. size. height
248+ //防止在结束刷新的时候,percent的跳跃
249+ if let oldOffset = change ? [ NSKeyValueChangeOldKey] ? . CGPointValue ( ) {
250+ let oldPercent = ( topShowOffsetY - oldOffset. y) / self . frame. size. height
251+ if oldPercent >= 1.0 && percent == 0.0 {
252+ return
253+ } else {
254+ self . delegate? . percentUpdateWhenNotRefreshing ( percent)
255+ }
256+ } else {
257+ self . delegate? . percentUpdateWhenNotRefreshing ( percent)
244258 }
245259 }
246260 // MARK: - KVO -
@@ -254,7 +268,6 @@ public class RefreshHeaderContainer:UIView{
254268 }
255269 // MARK: - API -
256270 func beginRefreshing( ) {
257- self . delegate? . willBeginRefreshing ( )
258271 if self . window != nil {
259272 self . state = . Refreshing
260273 } else {
@@ -264,7 +277,7 @@ public class RefreshHeaderContainer:UIView{
264277 }
265278 }
266279 func endRefreshing( result: RefreshResult ) {
267- self . delegate? . willEndRefreshing ( result)
280+ self . delegate? . didBeginEndRefershingAnimation ( result)
268281 self . state = . Idle
269282 }
270283}
0 commit comments