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

Commit 04a65ba

Browse files
Add custom footer Demo
1 parent bc921ae commit 04a65ba

9 files changed

Lines changed: 163 additions & 12 deletions

File tree

Demo/Demo.xcodeproj/project.pbxproj

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,8 @@
5151
B3B544AD1F062A9800408912 /* YoukuTableViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = B3B543D11F062A9700408912 /* YoukuTableViewController.swift */; };
5252
B3B544AE1F062A9800408912 /* LaunchScreen.strings in Resources */ = {isa = PBXBuildFile; fileRef = B3B543D21F062A9700408912 /* LaunchScreen.strings */; };
5353
B3B544AF1F062A9800408912 /* Main.strings in Resources */ = {isa = PBXBuildFile; fileRef = B3B543D41F062A9700408912 /* Main.strings */; };
54+
B3E751CD1FB999F5009D3A81 /* NeteaseNewsFooter.swift in Sources */ = {isa = PBXBuildFile; fileRef = B3E751CC1FB999F5009D3A81 /* NeteaseNewsFooter.swift */; };
55+
B3E751CF1FB99A22009D3A81 /* NeteaseFooterController.swift in Sources */ = {isa = PBXBuildFile; fileRef = B3E751CE1FB99A22009D3A81 /* NeteaseFooterController.swift */; };
5456
/* End PBXBuildFile section */
5557

5658
/* Begin PBXContainerItemProxy section */
@@ -130,6 +132,8 @@
130132
B3B543D11F062A9700408912 /* YoukuTableViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = YoukuTableViewController.swift; path = Demo/YoukuTableViewController.swift; sourceTree = "<group>"; };
131133
B3B543D31F062A9700408912 /* zh-Hans */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = "zh-Hans"; path = "zh-Hans.lproj/LaunchScreen.strings"; sourceTree = "<group>"; };
132134
B3B543D51F062A9700408912 /* zh-Hans */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = "zh-Hans"; path = "zh-Hans.lproj/Main.strings"; sourceTree = "<group>"; };
135+
B3E751CC1FB999F5009D3A81 /* NeteaseNewsFooter.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NeteaseNewsFooter.swift; sourceTree = "<group>"; };
136+
B3E751CE1FB99A22009D3A81 /* NeteaseFooterController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NeteaseFooterController.swift; sourceTree = "<group>"; };
133137
/* End PBXFileReference section */
134138

135139
/* Begin PBXFrameworksBuildPhase section */
@@ -190,6 +194,7 @@
190194
B38F55011F976DFF00993075 /* Custom */ = {
191195
isa = PBXGroup;
192196
children = (
197+
B3E751CB1FB999CE009D3A81 /* CustomFooter */,
193198
B38F55031F976E3200993075 /* Taobao */,
194199
B38F55081F976E6500993075 /* Elastic */,
195200
B38F55071F976E5D00993075 /* Yahoo */,
@@ -309,6 +314,15 @@
309314
path = ..;
310315
sourceTree = "<group>";
311316
};
317+
B3E751CB1FB999CE009D3A81 /* CustomFooter */ = {
318+
isa = PBXGroup;
319+
children = (
320+
B3E751CC1FB999F5009D3A81 /* NeteaseNewsFooter.swift */,
321+
B3E751CE1FB99A22009D3A81 /* NeteaseFooterController.swift */,
322+
);
323+
name = CustomFooter;
324+
sourceTree = "<group>";
325+
};
312326
/* End PBXGroup section */
313327

314328
/* Begin PBXNativeTarget section */
@@ -421,6 +435,7 @@
421435
B3B543E31F062A9800408912 /* BaseTableViewController.swift in Sources */,
422436
B3B543E41F062A9800408912 /* ConfigBannerController.swift in Sources */,
423437
B3B543EB1F062A9800408912 /* DefaultTableViewController.swift in Sources */,
438+
B3E751CD1FB999F5009D3A81 /* NeteaseNewsFooter.swift in Sources */,
424439
B3B544AD1F062A9800408912 /* YoukuTableViewController.swift in Sources */,
425440
B3B543EC1F062A9800408912 /* DefaultWebViewController.swift in Sources */,
426441
B3B5442F1F062A9800408912 /* QQVideoRefreshHeader.swift in Sources */,
@@ -431,6 +446,7 @@
431446
B3B544A31F062A9800408912 /* TaoBaoRefreshHeader.swift in Sources */,
432447
B3B544A51F062A9800408912 /* Util.swift in Sources */,
433448
B3B544A41F062A9800408912 /* TaobaoTableViewController.swift in Sources */,
449+
B3E751CF1FB99A22009D3A81 /* NeteaseFooterController.swift in Sources */,
434450
B3B543EE1F062A9800408912 /* DianpingTableviewController.swift in Sources */,
435451
B3B544A71F062A9800408912 /* YahooWeatherRefreshHeader.swift in Sources */,
436452
B3B5442E1F062A9800408912 /* MainViewController.swift in Sources */,

Demo/Demo/BaseTableViewController.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
import UIKit
1010

1111
class BaseTableViewController: UITableViewController {
12-
var models = [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15]
12+
var models = [1,2,3,4,5,6,7,8,9,10]
1313

1414
override func viewDidLoad() {
1515
super.viewDidLoad()

Demo/Demo/MainViewController.swift

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,14 +33,15 @@ class MainViewController: UITableViewController {
3333
sectionTitle:"Config Default",
3434
rowsTitles: ["Header/Footer","Left/Right"],
3535
rowsTargetControlerNames:["ConfigDefaultHeaderFooterController","ConfigBannerController"])
36-
let section3 = SectionModel(rowsCount: 5,
36+
let section3 = SectionModel(rowsCount: 6,
3737
sectionTitle:"Customize",
38-
rowsTitles: ["YahooWeather","Youku","TaoBao","QQ Video","DianPing"],
38+
rowsTitles: ["YahooWeather","Youku","TaoBao","QQ Video","DianPing","Netease Footer"],
3939
rowsTargetControlerNames:["YahooWeatherTableViewController",
4040
"YoukuTableViewController",
4141
"TaobaoTableViewController",
4242
"QQVideoTableviewController",
43-
"DianpingTableviewController"])
43+
"DianpingTableviewController",
44+
"NeteaseFooterController"])
4445
models.append(section0)
4546
models.append(section1)
4647
models.append(section2)

Demo/NeteaseFooterController.swift

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
//
2+
// NeteaseFooterController.swift
3+
// Demo
4+
//
5+
// Created by Leo on 2017/11/13.
6+
// Copyright © 2017年 Leo. All rights reserved.
7+
//
8+
9+
import UIKit
10+
11+
class NeteaseFooterController: BaseTableViewController {
12+
13+
override func viewDidLoad() {
14+
super.viewDidLoad()
15+
self.tableView.configRefreshFooter(with: NeteaseNewsFooter()) { [weak self] in
16+
delay(2.0, closure: {
17+
self?.models.append(random100())
18+
self?.tableView.reloadData()
19+
if let count = self?.models.count, count == 12{
20+
self?.tableView.switchRefreshFooter(to: .noMoreData)
21+
}else{
22+
self?.tableView.switchRefreshFooter(to: .normal)
23+
}
24+
});
25+
};
26+
}
27+
}

Demo/NeteaseNewsFooter.swift

Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
//
2+
// NeteaseNewsFooter.swift
3+
// Demo
4+
//
5+
// Created by Leo on 2017/11/13.
6+
// Copyright © 2017年 Leo. All rights reserved.
7+
//
8+
9+
import UIKit
10+
import PullToRefreshKit
11+
12+
class NeteaseNewsFooter: UIView, RefreshableFooter {
13+
var containerView = UIView()
14+
var textlabel = UILabel()
15+
var shapeLayer = CAShapeLayer()
16+
override init(frame: CGRect) {
17+
super.init(frame: frame)
18+
addSubview(containerView)
19+
textlabel.font = UIFont.systemFont(ofSize: 15)
20+
textlabel.textColor = UIColor.darkGray
21+
containerView.layer.cornerRadius = 4.0;
22+
containerView.layer.masksToBounds = true
23+
containerView.layer.shadowOffset = CGSize(width: 2.0, height: 2.0)
24+
containerView.layer.shadowRadius = 10.0;
25+
containerView.layer.shadowColor = UIColor.black.cgColor;
26+
containerView.layer.shadowOpacity = 0.20;
27+
containerView.layer.addSublayer(shapeLayer)
28+
containerView.layer.borderColor = UIColor.black.withAlphaComponent(0.2).cgColor
29+
containerView.layer.borderWidth = 0.5
30+
containerView.addSubview(textlabel)
31+
setUpCircleLayer()
32+
textlabel.text = "上拉加载更多"
33+
shapeLayer.isHidden = true
34+
}
35+
36+
override func layoutSubviews() {
37+
super.layoutSubviews()
38+
containerView.frame = CGRect(x: 8.0, y: 10.0, width: self.frame.width - 16.0, height: self.frame.size.height - 20.0)
39+
textlabel.sizeToFit()
40+
textlabel.center = CGPoint(x: containerView.frame.size.width / 2.0, y: containerView.frame.size.height/2.0)
41+
shapeLayer.position = CGPoint(x: textlabel.frame.origin.x - 30.0, y: containerView.frame.size.height/2.0 + 10.0)
42+
}
43+
public required init?(coder aDecoder: NSCoder) {
44+
fatalError("init(coder:) has not been implemented")
45+
}
46+
func setUpCircleLayer(){
47+
let bezierPath = UIBezierPath(arcCenter: CGPoint(x: 20, y: 20),
48+
radius: 12.0,
49+
startAngle:-CGFloat.pi/2,
50+
endAngle: CGFloat.pi/2.0 * 3.0,
51+
clockwise: true)
52+
shapeLayer.path = bezierPath.cgPath
53+
shapeLayer.strokeColor = UIColor.lightGray.cgColor
54+
shapeLayer.fillColor = UIColor.clear.cgColor
55+
shapeLayer.strokeStart = 0.3
56+
shapeLayer.strokeEnd = 0.8
57+
shapeLayer.lineWidth = 1.0
58+
shapeLayer.lineCap = kCALineCapRound
59+
shapeLayer.bounds = CGRect(x: 0, y: 0,width: 40, height: 40)
60+
shapeLayer.anchorPoint = CGPoint(x: 0.5, y: 0.5)
61+
layer.addSublayer(shapeLayer)
62+
}
63+
64+
// MARK: - RefreshableHeader -
65+
66+
func heightForFooter() -> CGFloat {
67+
return 65
68+
}
69+
70+
func didUpdateToNoMoreData() {
71+
textlabel.text = "到底了..."
72+
shapeLayer.isHidden = true
73+
shapeLayer.removeAnimation(forKey: "rotate")
74+
setNeedsLayout()
75+
}
76+
77+
func didResetToDefault() {
78+
textlabel.text = "上拉加载更多"
79+
shapeLayer.isHidden = true
80+
shapeLayer.removeAnimation(forKey: "rotate")
81+
setNeedsLayout()
82+
}
83+
84+
func didEndRefreshing() {
85+
textlabel.text = "上拉加载更多"
86+
shapeLayer.isHidden = true
87+
shapeLayer.removeAnimation(forKey: "rotate")
88+
setNeedsLayout()
89+
}
90+
91+
func didBeginRefreshing() {
92+
textlabel.text = "正在加载中..."
93+
let rotateAnimation = CABasicAnimation(keyPath: "transform.rotation.z")
94+
rotateAnimation.toValue = NSNumber(value: Double.pi * 2.0)
95+
rotateAnimation.duration = 0.6
96+
rotateAnimation.isCumulative = true
97+
rotateAnimation.repeatCount = 10000000
98+
shapeLayer.add(rotateAnimation, forKey: "rotate")
99+
setNeedsLayout()
100+
shapeLayer.isHidden = false
101+
}
102+
103+
func shouldBeginRefreshingWhenScroll() -> Bool {
104+
return true
105+
}
106+
107+
}

Source/Classes/Footer.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ import UIKit
3232
func didBeginRefreshing()
3333

3434
/**
35-
当Scroll触发刷新,这个方法返回是否需要刷新
35+
当Scroll触发刷新,这个方法返回是否需要刷新(比如你只想要点击刷新)
3636
*/
3737
func shouldBeginRefreshingWhenScroll()->Bool
3838
}

Source/Classes/Left.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ public protocol RefreshableLeftRight:class{
1313
/**
1414
触发动作的距离,对于header/footer来讲,就是视图的高度;对于left/right来讲,就是视图的宽度
1515
*/
16-
func heightForComponent()->CGFloat
16+
func widthForComponent()->CGFloat
1717
/**
1818
已经开始执行刷新逻辑,在一次刷新中,只会调用一次
1919
*/
@@ -76,10 +76,10 @@ open class DefaultRefreshLeft: UIView, RefreshableLeftRight {
7676
imageView.center = CGPoint(x: 40,y: frame.size.height/2)
7777
}
7878
// MARK: - RefreshableLeftRight Protocol -
79-
open func heightForComponent() -> CGFloat {
80-
return PullToRefreshKitConst.defaultHeaderHeight
79+
open func widthForComponent() -> CGFloat {
80+
return PullToRefreshKitConst.defaultRightWidth
8181
}
82-
open func percentUpdateDuringScrolling(_ percent:CGFloat){
82+
open func percentUpdateDuringScrolling(_ percent:CGFloat){
8383
if percent > 1.0{
8484
guard self.imageView.transform == CGAffineTransform.identity else{
8585
return

Source/Classes/PullToRefresh.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ public extension UIScrollView{
118118
oldContain?.removeFromSuperview()
119119
let frame = CGRect(x: -1.0 * refrehser.frame.size.width,
120120
y: 0.0,
121-
width: refrehser.frame.size.width,
121+
width: refrehser.widthForComponent(),
122122
height: self.frame.height)
123123
let containComponent = RefreshLeftContainer(frame: frame)
124124
containComponent.tag = PullToRefreshKitConst.leftTag

Source/Classes/Right.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,8 @@ open class DefaultRefreshRight:UIView, RefreshableLeftRight {
4747
imageView.center = CGPoint(x: 10,y: frame.size.height/2)
4848
}
4949
// MARK: - RefreshableLeftRight Protocol -
50-
open func heightForComponent() -> CGFloat {
51-
return PullToRefreshKitConst.defaultHeaderHeight
50+
open func widthForComponent() -> CGFloat {
51+
return PullToRefreshKitConst.defaultRightWidth
5252
}
5353
open func percentUpdateDuringScrolling(_ percent:CGFloat){
5454
if percent > 1.0{

0 commit comments

Comments
 (0)