Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 906db3b

Browse files
committed
Readme 调整
1 parent c6060af commit 906db3b

26 files changed

+623
-607
lines changed

GTMRefresh.podspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
Pod::Spec.new do |s|
44

55
s.name = "GTMRefresh"
6-
s.version = "1.1.2"
6+
s.version = "1.1.3"
77
s.summary = "swift 实现的上拉刷新,下拉加载动效库"
88

99
s.homepage = "https://github.com/GTMYang/GTMRefresh"

GTMRefresh.xcodeproj/project.pbxproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
26B9A97E1DF7E1B200D0BAA6 /* GTMRefreshHeader.swift in Sources */ = {isa = PBXBuildFile; fileRef = 26B9A97D1DF7E1B200D0BAA6 /* GTMRefreshHeader.swift */; };
4444
26B9A9801DF7E1C000D0BAA6 /* GTMLoadMoreFooter.swift in Sources */ = {isa = PBXBuildFile; fileRef = 26B9A97F1DF7E1C000D0BAA6 /* GTMLoadMoreFooter.swift */; };
4545
26B9A9821DF8088900D0BAA6 /* GTMRefreshConstant.swift in Sources */ = {isa = PBXBuildFile; fileRef = 26B9A9811DF8088900D0BAA6 /* GTMRefreshConstant.swift */; };
46+
26EEEF851F399BCF00A94AE5 /* GTMRefreshStyle.swift in Sources */ = {isa = PBXBuildFile; fileRef = 26EEEF841F399BCF00A94AE5 /* GTMRefreshStyle.swift */; };
4647
26F3498B1DFAF37E004C8CF1 /* YahooWeatherRefreshHeader.swift in Sources */ = {isa = PBXBuildFile; fileRef = 26F3498A1DFAF37E004C8CF1 /* YahooWeatherRefreshHeader.swift */; };
4748
26F3498D1DFAF39F004C8CF1 /* YahooWeatherTableViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 26F3498C1DFAF39F004C8CF1 /* YahooWeatherTableViewController.swift */; };
4849
26F349FE1DFAF3D5004C8CF1 /* sun_00000.png in Resources */ = {isa = PBXBuildFile; fileRef = 26F3498F1DFAF3D5004C8CF1 /* sun_00000.png */; };
@@ -296,6 +297,7 @@
296297
26B9A97D1DF7E1B200D0BAA6 /* GTMRefreshHeader.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = GTMRefreshHeader.swift; sourceTree = "<group>"; };
297298
26B9A97F1DF7E1C000D0BAA6 /* GTMLoadMoreFooter.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = GTMLoadMoreFooter.swift; sourceTree = "<group>"; };
298299
26B9A9811DF8088900D0BAA6 /* GTMRefreshConstant.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = GTMRefreshConstant.swift; sourceTree = "<group>"; };
300+
26EEEF841F399BCF00A94AE5 /* GTMRefreshStyle.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = GTMRefreshStyle.swift; sourceTree = "<group>"; };
299301
26F3498A1DFAF37E004C8CF1 /* YahooWeatherRefreshHeader.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = YahooWeatherRefreshHeader.swift; sourceTree = "<group>"; };
300302
26F3498C1DFAF39F004C8CF1 /* YahooWeatherTableViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = YahooWeatherTableViewController.swift; sourceTree = "<group>"; };
301303
26F3498F1DFAF3D5004C8CF1 /* sun_00000.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = sun_00000.png; sourceTree = "<group>"; };
@@ -640,6 +642,7 @@
640642
26B9A97D1DF7E1B200D0BAA6 /* GTMRefreshHeader.swift */,
641643
26B9A97F1DF7E1C000D0BAA6 /* GTMLoadMoreFooter.swift */,
642644
26B9A97B1DF7DD9900D0BAA6 /* GTMRefreshExtension.swift */,
645+
26EEEF841F399BCF00A94AE5 /* GTMRefreshStyle.swift */,
643646
2671154D1DF6AE2E00F27CEA /* Supporting Files */,
644647
);
645648
path = GTMRefresh;
@@ -1171,6 +1174,7 @@
11711174
26B9A9821DF8088900D0BAA6 /* GTMRefreshConstant.swift in Sources */,
11721175
26B9A9781DF7AFDA00D0BAA6 /* GTMRefreshComponent.swift in Sources */,
11731176
26B9A9801DF7E1C000D0BAA6 /* GTMLoadMoreFooter.swift in Sources */,
1177+
26EEEF851F399BCF00A94AE5 /* GTMRefreshStyle.swift in Sources */,
11741178
267115531DF6AE4E00F27CEA /* README.md in Sources */,
11751179
);
11761180
runOnlyForDeploymentPostprocessing = 0;

GTMRefresh/GTMLoadMoreFooter.swift

Lines changed: 29 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,10 @@ import UIKit
2020
func contentHeith() -> CGFloat
2121
}
2222

23-
public protocol GTMLoadMoreFooterDelegate: class {
24-
func loadMore()
25-
}
26-
2723
open class GTMLoadMoreFooter: GTMRefreshComponent, SubGTMRefreshComponentProtocol {
2824

29-
weak var delegate: GTMLoadMoreFooterDelegate?
3025
/// 加载更多Block
31-
// var loadMoreBlock: () -> Void = {}
26+
var loadMoreBlock: () -> Void = {}
3227

3328
var contentView: UIView = {
3429
let view = UIView()
@@ -75,8 +70,7 @@ open class GTMLoadMoreFooter: GTMRefreshComponent, SubGTMRefreshComponentProtoco
7570
scrollV.mj_insetB = toInsetB
7671
scrollV.mj_offsetY = self.footerCloseOffsetY + self.mj_h
7772
}, completion: { (isComplet) in
78-
//self.loadMoreBlock()
79-
self.delegate?.loadMore()
73+
self.loadMoreBlock()
8074
self.subProtocol?.toRefreshingState?()
8175
})
8276

@@ -108,7 +102,7 @@ open class GTMLoadMoreFooter: GTMRefreshComponent, SubGTMRefreshComponentProtoco
108102
super.willMove(toSuperview: newSuperview)
109103

110104
self.scollViewContentSizeDidChange(change: nil)
111-
105+
112106
}
113107

114108
// MARK: Layout
@@ -209,21 +203,41 @@ open class GTMLoadMoreFooter: GTMRefreshComponent, SubGTMRefreshComponentProtoco
209203
}
210204
}
211205
}
212-
206+
213207
}
214208

215209

216210

217211
class DefaultGTMLoadMoreFooter: GTMLoadMoreFooter, SubGTMLoadMoreFooterProtocol {
218212

219-
var pullUpToRefreshText: String = GTMRLocalize("pullUpToRefresh")
213+
var pullUpToRefreshText: String = GTMRLocalize("pullUpToRefresh")
220214
public var loaddingText: String = GTMRLocalize("loadMore")
221215
public var noMoreDataText: String = GTMRLocalize("noMoreData")
222216
public var releaseLoadMoreText: String = GTMRLocalize("releaseLoadMore")
223217

218+
var txtColor: UIColor? {
219+
didSet {
220+
if let color = txtColor {
221+
self.messageLabel.textColor = color
222+
}
223+
}
224+
}
225+
var idleImage: UIImage? {
226+
didSet {
227+
if let idleImg = idleImage {
228+
self.pullingIndicator.image = idleImg
229+
}
230+
}
231+
}
232+
233+
224234
lazy var pullingIndicator: UIImageView = {
225235
let pindicator = UIImageView()
226-
pindicator.image = UIImage(named: "arrow_down", in: Bundle(for: GTMLoadMoreFooter.self), compatibleWith: nil)
236+
if let img = self.idleImage {
237+
pindicator.image = img
238+
} else {
239+
pindicator.image = UIImage(named: "arrow_down", in: Bundle(for: GTMLoadMoreFooter.self), compatibleWith: nil)
240+
}
227241
return pindicator
228242
}()
229243

@@ -265,7 +279,7 @@ class DefaultGTMLoadMoreFooter: GTMLoadMoreFooter, SubGTMLoadMoreFooterProtocol
265279
return
266280
}
267281

268-
self.pullingIndicator.transform = CGAffineTransform(rotationAngle: CGFloat(-M_PI+0.000001))
282+
self.pullingIndicator.transform = CGAffineTransform(rotationAngle: CGFloat(-Double.pi+0.000001))
269283
}
270284

271285
// MARK: Layout
@@ -298,7 +312,7 @@ class DefaultGTMLoadMoreFooter: GTMLoadMoreFooter, SubGTMLoadMoreFooterProtocol
298312

299313
messageLabel.text = self.pullUpToRefreshText
300314
UIView.animate(withDuration: 0.4, animations: {
301-
self.pullingIndicator.transform = CGAffineTransform(rotationAngle: CGFloat(-M_PI+0.000001))
315+
self.pullingIndicator.transform = CGAffineTransform(rotationAngle: CGFloat(-Double.pi+0.000001))
302316
})
303317
}
304318
func toNoMoreDataState() {
@@ -319,5 +333,5 @@ class DefaultGTMLoadMoreFooter: GTMLoadMoreFooter, SubGTMLoadMoreFooterProtocol
319333

320334
messageLabel.text = self.loaddingText
321335
}
322-
336+
323337
}

GTMRefresh/GTMRefreshComponent.swift

Lines changed: 14 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -30,18 +30,10 @@ public protocol SubGTMRefreshComponentProtocol {
3030

3131
open class GTMRefreshComponent: UIView {
3232

33-
public weak var scrollView: UIScrollView?
33+
public var scrollView: UIScrollView?
3434

3535
public var scrollViewOriginalInset: UIEdgeInsets?
3636

37-
public var observerOpen: Bool = false {
38-
willSet {
39-
if observerOpen != newValue {
40-
newValue ? self.addObserver() : self.removeAbserver()
41-
}
42-
}
43-
}
44-
4537
var state: GTMRefreshState = .idle
4638

4739
// MARK: Life Cycle
@@ -59,10 +51,6 @@ open class GTMRefreshComponent: UIView {
5951
fatalError("init(coder:) has not been implemented")
6052
}
6153

62-
deinit {
63-
print("Deinit of GTMRefreshComponent")
64-
}
65-
6654
override open func draw(_ rect: CGRect) {
6755
super.draw(rect)
6856

@@ -75,11 +63,13 @@ open class GTMRefreshComponent: UIView {
7563
override open func willMove(toSuperview newSuperview: UIView?) {
7664
super.willMove(toSuperview: newSuperview)
7765

78-
// guard newSuperview == nil || newSuperview is UIScrollView else {
79-
// return
80-
// }
66+
guard newSuperview is UIScrollView else {
67+
return
68+
}
69+
70+
self.removeAbserver()
8171

82-
guard newSuperview is UIScrollView, let superView = newSuperview else {
72+
guard let superView = newSuperview else {
8373
return
8474
}
8575

@@ -91,25 +81,22 @@ open class GTMRefreshComponent: UIView {
9181
self.scrollView?.alwaysBounceVertical = true
9282
self.scrollViewOriginalInset = self.scrollView?.contentInset
9383

94-
self.observerOpen = true
84+
self.addObserver()
9585
}
9686

9787

9888
// MARK: KVO
9989

100-
func addObserver() {
90+
private func addObserver() {
10191
scrollView?.addObserver(self, forKeyPath: GTMRefreshConstant.keyPathContentOffset, options: .new, context: nil)
10292
scrollView?.addObserver(self, forKeyPath: GTMRefreshConstant.keyPathContentSize, options: .new, context: nil)
10393
}
10494

105-
func removeAbserver() {
106-
if let scrollV = scrollView {
107-
scrollV.removeObserver(self, forKeyPath: GTMRefreshConstant.keyPathContentOffset)
108-
scrollV.removeObserver(self, forKeyPath: GTMRefreshConstant.keyPathContentSize)
109-
}
95+
private func removeAbserver() {
96+
scrollView?.removeObserver(self, forKeyPath: GTMRefreshConstant.keyPathContentOffset)
97+
scrollView?.removeObserver(self, forKeyPath: GTMRefreshConstant.keyPathContentSize)
11098
}
11199

112-
113100
override open func observeValue(forKeyPath keyPath: String?, of object: Any?, change: [NSKeyValueChangeKey : Any]?, context: UnsafeMutableRawPointer?) {
114101
guard isUserInteractionEnabled else {
115102
return
@@ -131,6 +118,6 @@ open class GTMRefreshComponent: UIView {
131118
}
132119
}
133120

134-
135-
121+
122+
136123
}

GTMRefresh/GTMRefreshConstant.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ class GTMRefreshConstant {
1616
static let keyPathContentOffset: String = "contentOffset"
1717
static let keyPathContentInset: String = "contentInset"
1818
static let keyPathContentSize: String = "contentSize"
19-
// static let keyPathPanState: String = "state"
19+
// static let keyPathPanState: String = "state"
2020

2121

2222
static var associatedObjectGtmHeader = 0

GTMRefresh/GTMRefreshExtension.swift

Lines changed: 9 additions & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -11,40 +11,20 @@ import ObjectiveC
1111

1212
extension UIScrollView {
1313

14-
override open func willMove(toSuperview newSuperview: UIView?) {
15-
super.willMove(toSuperview: newSuperview)
16-
// print("table willMove toSuperview \(newSuperview)")
17-
if newSuperview == nil {
18-
self.gtmHeader?.observerOpen = false
19-
self.gtmFooter?.observerOpen = false
20-
21-
self.gtmHeader = nil
22-
self.gtmFooter = nil
23-
}
24-
}
25-
26-
private var gtmHeader: GTMRefreshHeader? {
14+
internal var gtmHeader: GTMRefreshHeader? {
2715
get {
2816
return objc_getAssociatedObject(self, &GTMRefreshConstant.associatedObjectGtmHeader) as? GTMRefreshHeader
2917
}
3018
set {
31-
if newValue == nil {
32-
objc_removeAssociatedObjects(gtmHeader)
33-
} else {
34-
objc_setAssociatedObject(self, &GTMRefreshConstant.associatedObjectGtmHeader, newValue, objc_AssociationPolicy.OBJC_ASSOCIATION_RETAIN_NONATOMIC)
35-
}
19+
objc_setAssociatedObject(self, &GTMRefreshConstant.associatedObjectGtmHeader, newValue, objc_AssociationPolicy.OBJC_ASSOCIATION_RETAIN_NONATOMIC)
3620
}
3721
}
38-
private var gtmFooter: GTMLoadMoreFooter? {
22+
internal var gtmFooter: GTMLoadMoreFooter? {
3923
get {
4024
return objc_getAssociatedObject(self, &GTMRefreshConstant.associatedObjectGtmFooter) as? GTMLoadMoreFooter
4125
}
4226
set {
43-
if newValue == nil {
44-
objc_removeAssociatedObjects(gtmFooter)
45-
} else {
46-
objc_setAssociatedObject(self, &GTMRefreshConstant.associatedObjectGtmFooter, newValue, objc_AssociationPolicy.OBJC_ASSOCIATION_RETAIN_NONATOMIC)
47-
}
27+
objc_setAssociatedObject(self, &GTMRefreshConstant.associatedObjectGtmFooter, newValue, objc_AssociationPolicy.OBJC_ASSOCIATION_RETAIN_NONATOMIC)
4828
}
4929
}
5030

@@ -54,7 +34,7 @@ extension UIScrollView {
5434
/// - refreshHeader: 下拉刷新动效View必须继承GTMRefreshHeader并且要实现SubGTMRefreshHeaderProtocol,不传值的时候默认使用 DefaultGTMRefreshHeader
5535
/// - refreshBlock: 刷新数据Block
5636
@discardableResult
57-
final public func gtm_addRefreshHeaderView(refreshHeader: GTMRefreshHeader? = DefaultGTMRefreshHeader(), delegate:GTMRefreshHeaderDelegate?) -> UIScrollView {
37+
final public func gtm_addRefreshHeaderView(refreshHeader: GTMRefreshHeader? = DefaultGTMRefreshHeader(), refreshBlock:@escaping () -> Void) -> UIScrollView {
5838
guard refreshHeader is SubGTMRefreshHeaderProtocol else {
5939
fatalError("refreshHeader must implement SubGTMRefreshHeaderProtocol")
6040
}
@@ -65,49 +45,23 @@ extension UIScrollView {
6545
gtmHeader?.removeFromSuperview()
6646

6747
if let header:GTMRefreshHeader = refreshHeader {
68-
// header.refreshBlock = refreshBlock
69-
header.delegate = delegate
48+
header.refreshBlock = refreshBlock
7049
self.insertSubview(header, at: 0)
7150
self.gtmHeader = header
7251
}
7352
}
7453
return self
7554
}
7655

77-
// 自定义header文字
78-
final public func setupHeaderText(pullDownToRefreshText: String? = nil,
79-
releaseToRefreshText: String? = nil,
80-
refreshSuccessText: String? = nil,
81-
refreshFailureText: String? = nil,
82-
refreshingText: String? = nil) {
83-
guard let defaultFooter = self.gtmHeader, defaultFooter is DefaultGTMRefreshHeader else {
84-
return
85-
}
86-
let header = defaultFooter as! DefaultGTMRefreshHeader
87-
if let txt = pullDownToRefreshText {
88-
header.pullDownToRefresh = txt
89-
}
90-
if let txt = releaseToRefreshText {
91-
header.releaseToRefresh = txt
92-
}
93-
if let txt = refreshSuccessText {
94-
header.refreshSuccess = txt
95-
}
96-
if let txt = refreshFailureText {
97-
header.refreshFailure = txt
98-
}
99-
if let txt = refreshingText {
100-
header.refreshing = txt
101-
}
102-
}
56+
10357

10458
/// 添加上拉加载
10559
///
10660
/// - Parameters:
10761
/// - loadMoreFooter: 上拉加载动效View必须继承GTMLoadMoreFooter,不传值的时候默认使用 DefaultGTMLoadMoreFooter
10862
/// - refreshBlock: 加载更多数据Block
10963
@discardableResult
110-
final public func gtm_addLoadMoreFooterView(loadMoreFooter: GTMLoadMoreFooter? = DefaultGTMLoadMoreFooter(), delegate:GTMLoadMoreFooterDelegate?) -> UIScrollView {
64+
final public func gtm_addLoadMoreFooterView(loadMoreFooter: GTMLoadMoreFooter? = DefaultGTMLoadMoreFooter(), loadMoreBlock:@escaping () -> Void) -> UIScrollView {
11165

11266
guard loadMoreFooter is SubGTMLoadMoreFooterProtocol else {
11367
fatalError("loadMoreFooter must implement SubGTMLoadMoreFooterProtocol")
@@ -120,39 +74,14 @@ extension UIScrollView {
12074
gtmFooter?.removeFromSuperview()
12175

12276
if let footer:GTMLoadMoreFooter = loadMoreFooter {
123-
// footer.loadMoreBlock = loadMoreBlock
124-
footer.delegate = delegate
77+
footer.loadMoreBlock = loadMoreBlock
12578
self.insertSubview(footer, at: 0)
12679
self.gtmFooter = footer
12780
}
12881
}
12982
return self
13083
}
13184

132-
// 自定义footer文字
133-
final public func setupFooterText(pullUpToRefreshText: String? = nil,
134-
loaddingText: String? = nil,
135-
noMoreDataText: String? = nil,
136-
releaseLoadMoreText: String? = nil) {
137-
guard let defaultFooter = self.gtmFooter, defaultFooter is DefaultGTMLoadMoreFooter else {
138-
return
139-
}
140-
let footer = defaultFooter as! DefaultGTMLoadMoreFooter
141-
if let txt = pullUpToRefreshText {
142-
footer.pullUpToRefreshText = txt
143-
footer.messageLabel.text = txt
144-
}
145-
if let txt = loaddingText {
146-
footer.loaddingText = txt
147-
}
148-
if let txt = noMoreDataText {
149-
footer.noMoreDataText = txt
150-
}
151-
if let txt = releaseLoadMoreText {
152-
footer.releaseLoadMoreText = txt
153-
}
154-
}
155-
15685
final public func triggerRefreshing(){
15786
self.gtmHeader?.autoRefreshing()
15887
}

0 commit comments

Comments
 (0)