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

Commit bc921ae

Browse files
Add height for Header function
1 parent ce68add commit bc921ae

19 files changed

Lines changed: 120 additions & 216 deletions

Demo/Demo.xcodeproj/project.pbxproj

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,6 @@
2222
B3B543E31F062A9800408912 /* BaseTableViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = B3B543071F062A9700408912 /* BaseTableViewController.swift */; };
2323
B3B543E41F062A9800408912 /* ConfigBannerController.swift in Sources */ = {isa = PBXBuildFile; fileRef = B3B543081F062A9700408912 /* ConfigBannerController.swift */; };
2424
B3B543E51F062A9800408912 /* ConfigHeaderFooterController.swift in Sources */ = {isa = PBXBuildFile; fileRef = B3B543091F062A9700408912 /* ConfigHeaderFooterController.swift */; };
25-
B3B543E61F062A9800408912 /* CurveMaskTableViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = B3B5430A1F062A9700408912 /* CurveMaskTableViewController.swift */; };
26-
B3B543E71F062A9800408912 /* CurveRefreshHeader.swift in Sources */ = {isa = PBXBuildFile; fileRef = B3B5430B1F062A9700408912 /* CurveRefreshHeader.swift */; };
2725
B3B543E81F062A9800408912 /* DefaultBannerController.swift in Sources */ = {isa = PBXBuildFile; fileRef = B3B5430C1F062A9700408912 /* DefaultBannerController.swift */; };
2826
B3B543E91F062A9800408912 /* DefaultCollectionViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = B3B5430D1F062A9700408912 /* DefaultCollectionViewController.swift */; };
2927
B3B543EA1F062A9800408912 /* DefaultScrollViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = B3B5430E1F062A9700408912 /* DefaultScrollViewController.swift */; };
@@ -102,8 +100,6 @@
102100
B3B543071F062A9700408912 /* BaseTableViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = BaseTableViewController.swift; path = Demo/BaseTableViewController.swift; sourceTree = "<group>"; };
103101
B3B543081F062A9700408912 /* ConfigBannerController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = ConfigBannerController.swift; path = Demo/ConfigBannerController.swift; sourceTree = "<group>"; };
104102
B3B543091F062A9700408912 /* ConfigHeaderFooterController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = ConfigHeaderFooterController.swift; path = Demo/ConfigHeaderFooterController.swift; sourceTree = "<group>"; };
105-
B3B5430A1F062A9700408912 /* CurveMaskTableViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = CurveMaskTableViewController.swift; path = Demo/CurveMaskTableViewController.swift; sourceTree = "<group>"; };
106-
B3B5430B1F062A9700408912 /* CurveRefreshHeader.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = CurveRefreshHeader.swift; path = Demo/CurveRefreshHeader.swift; sourceTree = "<group>"; };
107103
B3B5430C1F062A9700408912 /* DefaultBannerController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = DefaultBannerController.swift; path = Demo/DefaultBannerController.swift; sourceTree = "<group>"; };
108104
B3B5430D1F062A9700408912 /* DefaultCollectionViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = DefaultCollectionViewController.swift; path = Demo/DefaultCollectionViewController.swift; sourceTree = "<group>"; };
109105
B3B5430E1F062A9700408912 /* DefaultScrollViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = DefaultScrollViewController.swift; path = Demo/DefaultScrollViewController.swift; sourceTree = "<group>"; };
@@ -199,7 +195,6 @@
199195
B38F55071F976E5D00993075 /* Yahoo */,
200196
B38F55061F976E4C00993075 /* Dianping */,
201197
B38F55021F976E2A00993075 /* QQVideo */,
202-
B38F55051F976E4300993075 /* Curve */,
203198
B38F55041F976E3A00993075 /* Youku */,
204199
);
205200
name = Custom;
@@ -232,15 +227,6 @@
232227
name = Youku;
233228
sourceTree = "<group>";
234229
};
235-
B38F55051F976E4300993075 /* Curve */ = {
236-
isa = PBXGroup;
237-
children = (
238-
B3B5430A1F062A9700408912 /* CurveMaskTableViewController.swift */,
239-
B3B5430B1F062A9700408912 /* CurveRefreshHeader.swift */,
240-
);
241-
name = Curve;
242-
sourceTree = "<group>";
243-
};
244230
B38F55061F976E4C00993075 /* Dianping */ = {
245231
isa = PBXGroup;
246232
children = (
@@ -444,15 +430,13 @@
444430
B3B544311F062A9800408912 /* RowModel.swift in Sources */,
445431
B3B544A31F062A9800408912 /* TaoBaoRefreshHeader.swift in Sources */,
446432
B3B544A51F062A9800408912 /* Util.swift in Sources */,
447-
B3B543E71F062A9800408912 /* CurveRefreshHeader.swift in Sources */,
448433
B3B544A41F062A9800408912 /* TaobaoTableViewController.swift in Sources */,
449434
B3B543EE1F062A9800408912 /* DianpingTableviewController.swift in Sources */,
450435
B3B544A71F062A9800408912 /* YahooWeatherRefreshHeader.swift in Sources */,
451436
B3B5442E1F062A9800408912 /* MainViewController.swift in Sources */,
452437
B3B544301F062A9800408912 /* QQVideoTableViewController.swift in Sources */,
453438
B3B543ED1F062A9800408912 /* DianpingRefreshHeader.swift in Sources */,
454439
B3B543D91F062A9700408912 /* AppDelegate.swift in Sources */,
455-
B3B543E61F062A9800408912 /* CurveMaskTableViewController.swift in Sources */,
456440
B3B543EF1F062A9800408912 /* ElasticHeaderTableViewController.swift in Sources */,
457441
B3B543E51F062A9800408912 /* ConfigHeaderFooterController.swift in Sources */,
458442
B3B544A81F062A9800408912 /* YahooWeatherTableViewController.swift in Sources */,

Demo/Demo/CurveMaskTableViewController.swift

Lines changed: 0 additions & 25 deletions
This file was deleted.

Demo/Demo/CurveRefreshHeader.swift

Lines changed: 0 additions & 95 deletions
This file was deleted.

Demo/Demo/DianpingRefreshHeader.swift

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,18 @@ class DianpingRefreshHeader:UIView,RefreshableHeader{
1515
override init(frame: CGRect) {
1616
super.init(frame: frame)
1717
imageView.frame = CGRect(x: 0, y: 0, width: 60, height: 60)
18-
imageView.center = CGPoint(x: self.bounds.width/2.0, y: self.bounds.height/2.0)
1918
addSubview(imageView)
2019
}
21-
20+
override func layoutSubviews() {
21+
super.layoutSubviews()
22+
imageView.center = CGPoint(x: self.bounds.width/2.0, y: self.bounds.height/2.0)
23+
}
2224
required init?(coder aDecoder: NSCoder) {
2325
fatalError("init(coder:) has not been implemented")
2426
}
2527
// MARK: - RefreshableHeader -
26-
func heightForRefreshingState()->CGFloat{
27-
return 70
28+
func heightForHeader() -> CGFloat {
29+
return 60.0
2830
}
2931
//监听百分比变化
3032
func percentUpdateDuringScrolling(_ percent:CGFloat){

Demo/Demo/DianpingTableviewController.swift

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,7 @@ class DianpingTableviewController:BaseTableViewController{
1313
override func viewDidLoad() {
1414
super.viewDidLoad()
1515
//Setup
16-
self.tableView.backgroundColor = UIColor(red: 232.0/255.0, green: 234.0/255.0, blue: 235.0/255.0, alpha: 1.0)
17-
let taobaoHeader = DianpingRefreshHeader(frame: CGRect(x: 0,y: 0,width: self.view.bounds.width,height: 60))
18-
self.tableView.configRefreshHeader(with: taobaoHeader) { [weak self] in
16+
self.tableView.configRefreshHeader(with: DianpingRefreshHeader()) { [weak self] in
1917
delay(1.5, closure: {
2018
self?.models = (self?.models.map({_ in random100()}))!
2119
self?.tableView.reloadData()

Demo/Demo/MainViewController.swift

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,10 @@ class MainViewController: UITableViewController {
3333
sectionTitle:"Config Default",
3434
rowsTitles: ["Header/Footer","Left/Right"],
3535
rowsTargetControlerNames:["ConfigDefaultHeaderFooterController","ConfigBannerController"])
36-
let section3 = SectionModel(rowsCount: 6,
36+
let section3 = SectionModel(rowsCount: 5,
3737
sectionTitle:"Customize",
38-
rowsTitles: ["YahooWeather","Curve Mask","Youku","TaoBao","QQ Video","DianPing"],
38+
rowsTitles: ["YahooWeather","Youku","TaoBao","QQ Video","DianPing"],
3939
rowsTargetControlerNames:["YahooWeatherTableViewController",
40-
"CurveMaskTableViewController",
4140
"YoukuTableViewController",
4241
"TaobaoTableViewController",
4342
"QQVideoTableviewController",

Demo/Demo/QQVideoRefreshHeader.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ class QQVideoRefreshHeader:UIView,RefreshableHeader{
2424
}
2525

2626
// MARK: - RefreshableHeader -
27-
func heightForRefreshingState()->CGFloat{
28-
return 50
27+
func heightForHeader() -> CGFloat {
28+
return 50.0
2929
}
3030
func stateDidChanged(_ oldState: RefreshHeaderState, newState: RefreshHeaderState) {
3131
if newState == .pulling{

Demo/Demo/TaoBaoRefreshHeader.swift

Lines changed: 26 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,24 +15,29 @@ class TaoBaoRefreshHeader:UIView,RefreshableHeader{
1515
fileprivate let arrowLayer = CAShapeLayer()
1616
fileprivate let textLabel = UILabel()
1717
fileprivate let strokeColor = UIColor(red: 135.0/255.0, green: 136.0/255.0, blue: 137.0/255.0, alpha: 1.0)
18+
fileprivate let imageView = UIImageView(frame:CGRect(x: 0, y: 0, width: 230, height: 35))
19+
1820
override init(frame: CGRect) {
1921
super.init(frame: frame)
2022
setUpCircleLayer()
2123
setUpArrowLayer()
22-
textLabel.frame = CGRect(x: 0,y: 0,width: 120, height: 40)
2324
textLabel.textAlignment = .center
2425
textLabel.textColor = UIColor.lightGray
2526
textLabel.font = UIFont.systemFont(ofSize: 14)
2627
textLabel.text = "下拉即可刷新..."
27-
let imageView = UIImageView(frame: CGRect(x: 0, y: 0, width: 230, height: 35))
2828
imageView.image = UIImage(named: "taobaoLogo")
2929
self.addSubview(imageView)
3030
self.addSubview(textLabel)
31+
32+
}
33+
override func layoutSubviews() {
34+
super.layoutSubviews()
3135
//放置Views和Layer
32-
imageView.center = CGPoint(x: frame.width/2, y: frame.height - 60 - 18)
33-
textLabel.center = CGPoint(x: frame.width/2 + 20, y: frame.height - 30)
34-
self.arrowLayer.position = CGPoint(x: frame.width/2 - 60, y: frame.height - 30)
35-
self.circleLayer.position = CGPoint(x: frame.width/2 - 60, y: frame.height - 30)
36+
textLabel.frame = CGRect(x: 0,y: 0,width: 120, height: 40)
37+
imageView.center = CGPoint(x: self.frame.width/2, y: self.frame.height - 60 - 18)
38+
textLabel.center = CGPoint(x: self.frame.width/2 + 20, y: self.frame.height - 30)
39+
self.arrowLayer.position = CGPoint(x: self.frame.width/2 - 60, y: self.frame.height - 30)
40+
self.circleLayer.position = CGPoint(x: self.frame.width/2 - 60, y: self.frame.height - 30)
3641
}
3742
func setUpArrowLayer(){
3843
let bezierPath = UIBezierPath()
@@ -72,9 +77,18 @@ class TaoBaoRefreshHeader:UIView,RefreshableHeader{
7277
}
7378

7479
// MARK: - RefreshableHeader -
75-
func heightForRefreshingState()->CGFloat{
76-
return 60
80+
func heightForHeader() -> CGFloat {
81+
return 100
7782
}
83+
84+
func heightForFireRefreshing() -> CGFloat {
85+
return 60.0
86+
}
87+
88+
func heightForRefreshingState() -> CGFloat {
89+
return 60.0
90+
}
91+
7892
func percentUpdateDuringScrolling(_ percent:CGFloat){
7993
let adjustPercent = max(min(1.0, percent),0.0)
8094
if adjustPercent == 1.0{
@@ -84,6 +98,7 @@ class TaoBaoRefreshHeader:UIView,RefreshableHeader{
8498
}
8599
self.circleLayer.strokeEnd = 0.05 + 0.9 * adjustPercent
86100
}
101+
87102
func didBeginRefreshingState(){
88103
self.circleLayer.strokeEnd = 0.95
89104
let rotateAnimation = CABasicAnimation(keyPath: "transform.rotation.z")
@@ -95,19 +110,22 @@ class TaoBaoRefreshHeader:UIView,RefreshableHeader{
95110
self.arrowLayer.isHidden = true
96111
textLabel.text = "刷新中..."
97112
}
113+
98114
func didBeginEndRefershingAnimation(_ result:RefreshResult){
99115
transitionWithOutAnimation {
100116
self.circleLayer.strokeEnd = 0.05
101117
};
102118
self.circleLayer.removeAllAnimations()
103119
}
120+
104121
func didCompleteEndRefershingAnimation(_ result:RefreshResult){
105122
transitionWithOutAnimation {
106123
self.circleLayer.strokeEnd = 0.05
107124
};
108125
self.arrowLayer.isHidden = false
109126
textLabel.text = "下拉即可刷新"
110127
}
128+
111129
func transitionWithOutAnimation(_ clousre:()->()){
112130
CATransaction.begin()
113131
CATransaction.setDisableActions(true)

Demo/Demo/TaobaoTableViewController.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ class TaobaoTableViewController:BaseTableViewController{
1212
override func viewDidLoad() {
1313
super.viewDidLoad()
1414
//Setup
15-
let taobaoHeader = TaoBaoRefreshHeader(frame: CGRect(x: 0,y: 0,width: self.view.bounds.width,height: 100))
15+
let taobaoHeader = TaoBaoRefreshHeader()
1616
self.tableView.configRefreshHeader(with: taobaoHeader) {
1717
self.models = self.models.map({_ in random100()})
1818
self.tableView.reloadData()

Demo/Demo/YahooWeatherRefreshHeader.swift

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,27 +18,38 @@ class YahooWeatherRefreshHeader: UIView,RefreshableHeader{
1818
override init(frame: CGRect) {
1919
super.init(frame: frame)
2020
self.backgroundColor = UIColor(white: 0.0, alpha: 0.25)
21-
logoImage.center = CGPoint(x: self.bounds.width/2.0, y: frame.height - 30 - 7.0)
22-
imageView.center = CGPoint(x: self.bounds.width/2.0 - 60.0, y: frame.height - 30)
2321
imageView.image = UIImage(named: "sun_000000")
2422
logoImage.image = UIImage(named: "yahoo_logo")
25-
label.frame = CGRect(x: logoImage.frame.origin.x, y: logoImage.frame.origin.y + logoImage.frame.height + 2,width: 200, height: 20)
2623
label.textColor = UIColor.white
2724
label.font = UIFont.systemFont(ofSize: 12)
2825
label.text = "Last update: 5 minutes ago"
2926
addSubview(imageView)
3027
addSubview(logoImage)
3128
addSubview(label)
3229
}
33-
30+
override func layoutSubviews() {
31+
super.layoutSubviews()
32+
imageView.center = CGPoint(x: self.bounds.width/2.0 - 60.0, y: frame.height - 30)
33+
logoImage.center = CGPoint(x: self.bounds.width/2.0, y: frame.height - 30 - 7.0)
34+
label.frame = CGRect(x: logoImage.frame.origin.x, y: logoImage.frame.origin.y + logoImage.frame.height + 2,width: 200, height: 20)
35+
}
3436
required init?(coder aDecoder: NSCoder) {
3537
fatalError("init(coder:) has not been implemented")
3638
}
3739

3840
// MARK: - RefreshableHeader -
39-
func heightForRefreshingState()->CGFloat{
40-
return 60
41+
func heightForHeader() -> CGFloat {
42+
return UIScreen.main.bounds.size.height
43+
}
44+
45+
func heightForFireRefreshing() -> CGFloat {
46+
return 60.0
4147
}
48+
49+
func heightForRefreshingState() -> CGFloat {
50+
return 60.0
51+
}
52+
4253
func percentUpdateDuringScrolling(_ percent: CGFloat) {
4354
let adjustPercent = max(min(1.0, percent),0.0)
4455
let index = Int(adjustPercent * 27)

0 commit comments

Comments
 (0)