下拉刷新汇总:https://www.jianshu.com/p/59ca096f0d05
=========系统自带的refresh========
let con:UIRefreshControl=UIRefreshControl.init(frame: CGRect.init(x: 0, y: 0, width: WIDTH, height: 150))
con.tintColor=UIColor.red//小转圈的颜色
con.attributedTitle=NSAttributedString.init(string: "shuax")//转圈下面的文字---也可以设置文字的颜色,大小等
tab.addSubview(con)
DispatchQueue.main.asyncAfter(deadline: DispatchTime.now()+2) {
con.endRefreshing()//停止刷新
con.beginRefreshing()//开始刷新
}
===============mjrefresh的使用=============
github下载地址:https://github.com/CoderMJLee/MJRefresh
mjrefresh参考:http://www.hangge.com/blog/cache/detail_1406.html
1.下拉刷新*****************简单的使用,不带图片动画
func normalHeaderRefresh(){
let header = MJRefreshNormalHeader()//这个是原生的样式,不能自定义gif图
header.setRefreshingTarget(self, refreshingAction: #selector(pulldownrefresh))
header.setTitle("正在加载", for: .pulling)
header.setTitle("加载完成", for: .refreshing)
tab.mj_header=header
}
//下拉刷新
@objc func pulldownrefresh(){
print("下拉刷新")
weak var weakSelf = self
//请求轮播数据
requestHomeHeadScrollData()
//请求头条消息
requestFirstTopInfo()
DispatchQueue.main.asyncAfter(deadline: DispatchTime.now()+3) {
weakSelf!.tab.mj_header.endRefreshing()
}
}
2.下拉刷新******************带动动画
//初始化下拉刷新/上拉加载
func initGifMJRefresh(){
let topGifheader = MJRefreshGifHeader()//这个可以设置下拉刷新的图片动画效果
//下拉刷新相关设置
topGifheader.setRefreshingTarget(self, refreshingAction: #selector(pulldownrefresh))
let imageNames = ["bankBlue","bankGreen","bankRed","appstart"]//这个是显示的动画,数组中页可以是单张图片
var idleImages = [UIImage]()
//添加动画图片
for i in 1...3 {
idleImages.append(UIImage(named:imageNames[i-1])!)
}
topGifheader.setImages(idleImages, for: .idle)//普通状态
topGifheader.setImages(idleImages, for: .pulling)//手向下拉的时候
topGifheader.setImages(idleImages, for: .refreshing)//正在刷新
// topGifheader.lastUpdatedTimeLabel.isHidden = true//隐藏上次更新的时间
// topGifheader.stateLabel.isHidden = true//隐藏状态文字
topGifheader.setTitle("下拉刷新", for: .idle)
topGifheader.setTitle("正在加载", for: .pulling)
topGifheader.setTitle("加载完成", for: .refreshing)
//将下拉刷新控件与 tableView控件绑定起来
self.tab.mj_header = topGifheader
}
//下拉刷新
@objc func pulldownrefresh(){
print("下拉刷新")
weak var weakSelf = self
//请求轮播数据
requestHomeHeadScrollData()
//请求头条消息
requestFirstTopInfo()
DispatchQueue.main.asyncAfter(deadline: DispatchTime.now()+3) {
weakSelf!.tab.mj_header.endRefreshing()
}
}
1.上拉刷新***************
//上拉加载
func initNormalAutoFooterRefresh(){
let footer = MJRefreshAutoNormalFooter()
//上刷新相关设置
footer.setRefreshingTarget(self, refreshingAction: #selector(pullUprefresh))
//self.bottom_footer.stateLabel.isHidden = true // 隐藏文字
//是否自动加载(默认为true,即表格滑到底部就自动加载,这个我建议关掉,要不然效果会不好)
footer.isAutomaticallyRefresh = false
footer.isAutomaticallyChangeAlpha = true //自动更改透明度
//修改文字
footer.setTitle("上拉加载", for: .idle)//普通闲置的状态
footer.setTitle("正在加载中", for: .refreshing)//正在刷新的状态
footer.setTitle("加载完成", for: .noMoreData)//数据加载完毕的状态
tab.mj_footer=footer
}
//上拉刷新
@objc func pullUprefresh(){
print("上拉刷新")
weak var weakSelf = self
DispatchQueue.main.asyncAfter(deadline: DispatchTime.now()+3) {
weakSelf!.tab.mj_footer.endRefreshing()
}
}
//上拉加载
func initNormalAutoFooterRefresh(){
let footer = MJRefreshAutoNormalFooter()
//上刷新相关设置
footer.setRefreshingTarget(self, refreshingAction: #selector(pullUprefresh))
//self.bottom_footer.stateLabel.isHidden = true // 隐藏文字
//是否自动加载(默认为true,即表格滑到底部就自动加载,这个我建议关掉,要不然效果会不好)
footer.isAutomaticallyRefresh = false
footer.isAutomaticallyChangeAlpha = true //自动更改透明度
//修改文字
footer.setTitle("上拉加载", for: .idle)//普通闲置的状态
footer.setTitle("正在加载中", for: .refreshing)//正在刷新的状态
footer.setTitle("加载完成", for: .noMoreData)//数据加载完毕的状态
tab.mj_footer=footer
}
//上拉刷新
@objc func pullUprefresh(){
print("上拉加载")
DispatchQueue.global().asyncAfter(deadline: .now() + 5) { [self] in
tab.mj_footer?.endRefreshing {
print("结束上拉")
}
}
}
//下拉刷新
func pulldownrefresh(){
let header=MJRefreshNormalHeader()
header.setRefreshingTarget(self, refreshingAction: #selector(pullDownrefresh))
header.isAutomaticallyChangeAlpha=true//自动更改透明度
//修改文字
header.setTitle("下拉舒心", for: .idle)//普通闲置的状态
header.setTitle("正在加载中", for: .refreshing)//正在刷新的状态
header.setTitle("加载完成", for: .noMoreData)//数据加载完毕的状态
tab.mj_header=header
}
@objc func pullDownrefresh(){
print("下拉刷新")
DispatchQueue.global().asyncAfter(deadline: .now() + 5) { [self] in
tab.mj_header?.endRefreshing {
print("结束下拉刷新")
}
}
}
==========refresher=========
GitHub 地址:https://github.com/jcavar/refresher
使用:直接把下载下来的代码中的Refresher文件夹拖入到自己的工程中
//下拉刷新
tab.addPullToRefreshWithAction {
print("shauaxin ")
}
//下拉刷新自定义view
// //GCD操作8秒后
// DispatchQueue.main.asyncAfter(deadline: DispatchTime.now()+8) {
// self.tab.stopPullToRefresh()//self.tab.startPullToRefresh()
// }
可以自定义:动画,View
====DGElasticPullToRefresh======
github地址:https://github.com/gontovnik/DGElasticPullToRefresh
=============SDRefreshView========
github地址:https://github.com/gsdios/SDRefreshView
==========BreakOutToRefresh=========
github地址:https://github.com/dasdom/BreakOutToRefresh
==========GearRefreshControl=========
github地址:https://github.com/andreamazz/GearRefreshControl
============pull-to-refresh====ESPullToRefresh======
github地址:https://github.com/eggswift/pull-to-refresh
=======PullToBounce======
github地址:https://github.com/entotsu/PullToBounce