@@ -13,13 +13,26 @@ public enum RefreshKitFooterText{
1313 case pullToRefresh
1414 case refreshing
1515 case noMoreData
16+ case tapToRefresh
1617}
18+
1719public class DefaultRefreshFooter : UIView , RefreshableFooter {
1820 public let spinner : UIActivityIndicatorView = UIActivityIndicatorView ( activityIndicatorStyle: . Gray)
1921 public let textLabel : UILabel = UILabel ( frame: CGRectMake ( 0 , 0 , 120 , 40 ) ) . SetUp {
2022 $0. font = UIFont . systemFontOfSize ( 14 )
2123 $0. textAlignment = . Center
2224 }
25+ public var needTapToLoadMore = false {
26+ didSet{
27+ tap. enabled = needTapToLoadMore
28+ if needTapToLoadMore{
29+ textLabel. text = textDic [ . tapToRefresh]
30+ } else {
31+ textLabel. text = textDic [ . pullToRefresh]
32+ }
33+ }
34+ }
35+ private var tap : UITapGestureRecognizer !
2336 private var textDic = [ RefreshKitFooterText: String] ( )
2437 /**
2538 This function can only be called before refreshing
@@ -37,28 +50,69 @@ public class DefaultRefreshFooter:UIView,RefreshableFooter{
3750 textDic [ . pullToRefresh] = PullToRefreshKitFooterString . pullToRefresh
3851 textDic [ . refreshing] = PullToRefreshKitFooterString . refreshing
3952 textDic [ . noMoreData] = PullToRefreshKitFooterString . noMoreData
53+ textDic [ . tapToRefresh] = PullToRefreshKitFooterString . tapToRefresh
4054 textLabel. text = textDic [ . pullToRefresh]
55+ tap = UITapGestureRecognizer ( target: self , action: #selector( DefaultRefreshFooter . catchTap ( _: ) ) )
56+ tap. enabled = needTapToLoadMore
57+ self . addGestureRecognizer ( tap)
4158 }
42- public required init ? ( coder aDecoder: NSCoder ) {
59+ public required init ? ( coder aDecoder: NSCoder ) {
4360 fatalError ( " init(coder:) has not been implemented " )
4461 }
62+ func catchTap( tap: UITapGestureRecognizer ) {
63+ let scrollView = self . superview? . superview as? UIScrollView
64+ scrollView? . beginFooterRefreshing ( )
65+ }
4566 // MARK: - Refreshable -
46- public func distanceToRefresh( ) -> CGFloat {
67+ public func distanceToRefresh( ) -> CGFloat {
4768 return PullToRefreshKitConst . defaultFooterHeight
4869 }
49- public func didBeginRefreshing( ) {
70+ public func didBeginRefreshing( ) {
5071 textLabel. text = textDic [ . refreshing] ;
5172 spinner. startAnimating ( )
5273 }
53- public func didEndRefreshing( ) {
54- textLabel. text = textDic [ . pullToRefresh]
74+ public func didEndRefreshing( ) {
75+ if needTapToLoadMore{
76+ textLabel. text = textDic [ . tapToRefresh]
77+ } else {
78+ textLabel. text = textDic [ . pullToRefresh]
79+ }
5580 spinner. stopAnimating ( )
5681 }
57- public func didUpdateToNoMoreData( ) {
82+ public func didUpdateToNoMoreData( ) {
5883 textLabel. text = textDic [ . noMoreData]
5984 }
60- public func didResetToDefault( ) {
61- textLabel. text = textDic [ . pullToRefresh]
85+ public func didResetToDefault( ) {
86+ if needTapToLoadMore{
87+ textLabel. text = textDic [ . tapToRefresh]
88+ } else {
89+ textLabel. text = textDic [ . pullToRefresh]
90+ }
91+ }
92+ public func shouldBeginRefreshingWhenScroll( ) -> Bool {
93+ return !needTapToLoadMore
94+ }
95+ // MARK: - Handle touch -
96+ public override func touchesBegan( touches: Set < UITouch > , withEvent event: UIEvent ? ) {
97+ super. touchesBegan ( touches, withEvent: event)
98+ guard needTapToLoadMore else {
99+ return
100+ }
101+ self . backgroundColor = UIColor . lightGrayColor ( ) . colorWithAlphaComponent ( 0.5 )
102+ }
103+ public override func touchesEnded( touches: Set < UITouch > , withEvent event: UIEvent ? ) {
104+ super. touchesEnded ( touches, withEvent: event)
105+ guard needTapToLoadMore else {
106+ return
107+ }
108+ self . backgroundColor = UIColor . whiteColor ( )
109+ }
110+ public override func touchesCancelled( touches: Set < UITouch > ? , withEvent event: UIEvent ? ) {
111+ super. touchesCancelled ( touches, withEvent: event)
112+ guard needTapToLoadMore else {
113+ return
114+ }
115+ self . backgroundColor = UIColor . whiteColor ( )
62116 }
63117}
64118class RefreshFooterContainer : UIView {
@@ -107,6 +161,7 @@ class RefreshFooterContainer:UIView{
107161 required init ? ( coder aDecoder: NSCoder ) {
108162 fatalError ( " init(coder:) has not been implemented " )
109163 }
164+
110165// MARK: - Life circle -
111166 override func drawRect( rect: CGRect ) {
112167 super. drawRect ( rect)
@@ -167,6 +222,10 @@ class RefreshFooterContainer:UIView{
167222 guard newOffset? . y > oldOffset? . y else {
168223 return
169224 }
225+ let shouldStart = self . delegate? . shouldBeginRefreshingWhenScroll ( )
226+ guard shouldStart! else {
227+ return
228+ }
170229 beginRefreshing ( )
171230 }
172231 }
@@ -181,10 +240,18 @@ class RefreshFooterContainer:UIView{
181240 let contentSize = attachedScrollView. contentSize
182241 if scrollInset. top + contentSize. height <= CGRectGetHeight ( attachedScrollView. frame) {
183242 if scrollOffset. y >= - 1 * scrollInset. top {
243+ let shouldStart = self . delegate? . shouldBeginRefreshingWhenScroll ( )
244+ guard shouldStart! else {
245+ return
246+ }
184247 beginRefreshing ( )
185248 }
186249 } else {
187250 if scrollOffset. y > contentSize. height + scrollInset. bottom - CGRectGetHeight( attachedScrollView. frame) {
251+ let shouldStart = self . delegate? . shouldBeginRefreshingWhenScroll ( )
252+ guard shouldStart! else {
253+ return
254+ }
188255 beginRefreshing ( )
189256 }
190257 }
0 commit comments