Skip to content
This repository was archived by the owner on Jul 1, 2020. It is now read-only.

Commit 3cd66e3

Browse files
Left/Right/Footer支持自定义,文档增加
1 parent 60664a6 commit 3cd66e3

3 files changed

Lines changed: 75 additions & 21 deletions

File tree

PullToRefreshKit.xcodeproj/project.pbxproj

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -107,12 +107,12 @@
107107
52BB292A1D364C260091F36B /* Classes */ = {
108108
isa = PBXGroup;
109109
children = (
110-
5238C7F81D3763BA00B3B4FE /* Const.swift */,
111-
5238C7F91D3763BA00B3B4FE /* Footer.swift */,
110+
5238C7FC1D3763BA00B3B4FE /* PullToRefreshKit.swift */,
112111
5238C7FA1D3763BA00B3B4FE /* Header.swift */,
112+
5238C7F91D3763BA00B3B4FE /* Footer.swift */,
113113
5238C7FB1D3763BA00B3B4FE /* Left.swift */,
114-
5238C7FC1D3763BA00B3B4FE /* PullToRefreshKit.swift */,
115114
5238C7FD1D3763BA00B3B4FE /* Right.swift */,
115+
5238C7F81D3763BA00B3B4FE /* Const.swift */,
116116
);
117117
name = Classes;
118118
sourceTree = "<group>";

README.md

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,9 @@ pod "PullToRefreshKit"
4444
###上拉加载
4545
```
4646
self.tableView.setUpFooterRefresh { [weak self] in
47-
delay(1.5, closure: {
48-
self?.tableView.endFooterRefreshing()
49-
})
47+
delay(1.5, closure: {
48+
self?.tableView.endFooterRefreshing()
49+
})
5050
}
5151
```
5252

@@ -84,8 +84,7 @@ Screenshot/gif2.gif" width="320">
8484

8585
例如,Demo工程[TaoBaoRefreshHeader.swift](https://github.com/LeoMobileDeveloper/PullToRefreshKit/blob/master/PullToRefreshKit/TaoBaoRefreshHeader.swift)中实现了淘宝App的下拉刷新例子。
8686

87-
88-
87+
你只需要根据协议提供的回调来更新时图的状态
8988

9089
## Author
9190

Source/Classes/PullToRefreshKit.swift

Lines changed: 68 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -10,34 +10,86 @@ import Foundation
1010
import UIKit
1111

1212
enum 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
}
1830
protocol RefreshAble:class{
31+
/**
32+
触发动作的距离,对于header/footer来讲,就是视图的高度;对于left/right来讲,就是视图的宽度
33+
*/
1934
func distanceToRefresh()->CGFloat
35+
/**
36+
已经开始执行刷新逻辑,在一次刷新中,只会调用一次
37+
*/
2038
func didBeginRefreshing()
2139
}
2240
protocol 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

2965
protocol RefreshableFooter:RefreshAble{
66+
/**
67+
不需要下拉加载更多的回调
68+
*/
3069
func didUpdateToNoMoreData()
70+
/**
71+
重新设置到常态的回调
72+
*/
3173
func didResetToDefault()
74+
/**
75+
结束刷新的回调
76+
*/
3277
func didEndRefreshing()
3378
}
3479

3580
protocol 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

4294
public protocol SetUp {}
4395
extension SetUp where Self: AnyObject {
@@ -85,6 +137,10 @@ extension UIScrollView{
85137
//Footer
86138
extension 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
130183
extension 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
151205
extension 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

Comments
 (0)