每次看到比较好看的刷新动画都感觉好厉害,今天有时间看了一下MJ的gif的动画刷新,原来很简单
基于MJRefresh 配置 GIF动画
prepare方法中
*设置JIF动画图片 setImages:
*设置title setTitle:
placeSubViews中设置
*设置GIFView属性
*设置StateLabel的属性
GifHeader
class RefreshAutoGi fHeader :MJRefreshGifHeader {
///初始化
override func prepare() {
super.prepare()
//图片数组
var images:[UIImage] = [UIImage]()
//遍历
for index in 0..<16{
let image = UIImage (named:”dropdown loading 0\ ( index) ")images.append (image!)}
//设置空闲状态的图片
setImages(images, for: .idle)
set Images (images, for: .refreshing)
setTitle("正在努力加载",for: .idle)
setTitle("正在努力加载",for: .pulling)
setTitle("正在努力加载",for: .refreshing)
setTitle("正在努力加载",for: . willRefresh)
setTitle("没有更多数据",for: .noMoreData)}
override func placeSubviews() {
super .placeSubviews()
gifView . contentMode = .center
gifView.frame = CGRect(x: 0, y: 4, width: mj_W, height: 25)
stateLabel.font = UIFont . systemFont (ofSize: 12)
stateLabel. frame三CGRect(x: e,y: 35, width: mi_ w, height: 14)
}
}
GifFooter
class RefreshAutoGifFooter : MJRefreshAutoGifFooter {
///初始化
override func prepare() {
super . prepare( )
//控件高度
mj_ h = 50.0
//图片数组
var images: [UIImage] = [UIImage]()
//遍历
for index in 0..<8{
let image = UIImage (named: "sendloading_ 18x18_ \( index)")images .append (image!)
}
//设置空闲状态的图片
setImages(images, for: .idle)
set Images (images, for: .refreshing
setTitle("正在努力加载",for: .idle)
setTitle("正在努力加载",for: .pulling)
setTitle("正在努力加载",for: .refreshing)
setTitle("正在努力加载",for: .willRefresh)
setTitle("没有更多数据",for: .noMoreData)}
override func placeSubviews() {
super .placeSubviews ()
gifView.x = 135
gifView.centerY = stateLabel . centerY
}
使用
//设置刷新
func setRefreshO) {
// header
let header = Ref reshAutoGifHeader f[weak self] in
Ne tworkTpol. loadApiNewsFeeds ( category: self! .newsTitle.category, ttFrom: . enterAuto)
{ (maxBehotTime smalVideos) in
if (sclf? .collectionView.mj , header.isRefreshing!
{self?. collectionView .mj. header . endRefreshing()}
self! . smallVideos s smallVideos
self ! . naxBehotTime e maxBehotTime
self!.collectionView .reloadData()
}
}
header? . lastUpdatedTimeLabel .isHidden =true
header? . beginRefreshing()
header?. isAutomaticallyChangeAlpha = true
collectionView .mj_header=header
效果
晓雯的这篇文章是来自微信公众号关于iOS开发。若有侵权请联系晓雯微信:Pingwen20删除