swift4.0仿头条下拉刷新效果

效果还差那么两丢丢
代码可以直接用

import UIKit
import MJRefresh
class TTMJTestVC: UIViewController {

    lazy var tableViewm:UITableView = {
        let tb = UITableView.init(frame: CGRect.zero, style: UITableViewStyle.plain)
        return tb;
    }()
    
    
    override func viewDidLoad() {
        super.viewDidLoad()

        configureTb()
        setMJ();
    }

    func configureTb() {
        self.view.addSubview(tableViewm)
        tableViewm.delegate = self;
        tableViewm.dataSource = self;
        tableViewm.backgroundColor = UIColor.white
        tableViewm.snp.makeConstraints { (make) in
            make.edges.equalToSuperview();
        }
        
    }

    func setMJ() {
        tableViewm.mj_header = MJRefreshNormalHeader.init(refreshingBlock: {
            
            DispatchQueue.main.asyncAfter(deadline: DispatchTime.now() + 1, execute: {
                self.endMJrefreshAction(scrollView: self.tableViewm, viewHeigh: 30, titles: "!!我爱你!!")
            })
        })
        
    }
    
    func endMJrefreshAction(scrollView:UIScrollView,viewHeigh:Int,titles:String) {
        scrollView.mj_header.isAutomaticallyChangeAlpha = true
        print(scrollView.mj_offsetY)
        print(scrollView.mj_header.mj_h)
        let mjhead = scrollView.mj_header
        
        UIView.animate(withDuration: 0.2, animations: {
        }) { (iscompletion) in
            
            var vv = mjhead?.viewWithTag(9999)
            var lb = mjhead?.viewWithTag(9998) as? UILabel
            
            if let _ = vv {vv?.isHidden = false }else{
                vv = UIView.init(frame: CGRect.init(x: SCREEN_WIDTH/4, y: 27, width: SCREEN_WIDTH/2, height: 27))
                vv?.backgroundColor = UIColor.blue.withAlphaComponent(0.6)
                vv?.tag = 9999;
                mjhead?.addSubview(vv!)
            }
            
            if let _ = lb {lb?.isHidden = false}else{
                lb = UILabel.init(frame: CGRect.init(x: 0, y: 27, width: SCREEN_WIDTH, height: 27))
                lb?.text = titles
                lb?.textColor = UIColor.red
                lb?.textAlignment = .center
                lb?.tag = 9998
                mjhead?.addSubview(lb!)
            }
            
            UIView.animate(withDuration: 0.15, animations: {
                vv!.transform = CGAffineTransform.init(scaleX: 2, y: 1)
            }, completion: { (isfinish) in
                
                DispatchQueue.main.asyncAfter(deadline: DispatchTime.now() + 2, execute: {
                    mjhead?.endRefreshing();
                    
                    DispatchQueue.main.asyncAfter(deadline: DispatchTime.now() + 1, execute: {
                        vv?.isHidden = true
                        lb?.isHidden = true
                        vv?.transform = CGAffineTransform.identity
                        
                    })
                })
                
            })
            
        }
       
        
    }
    
}

extension TTMJTestVC:UITableViewDataSource{
    func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return 10
    }
    
    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        var cell:TTFDCell? = tableView.dequeueReusableCell(withIdentifier:String.init(describing: TTFDCell.self)) as? TTFDCell
        if let _ = cell {}else{
            cell = Bundle.main.loadNibNamed(String.init(describing: TTFDCell.self), owner: nil, options: nil)?.first as? TTFDCell
        }
        setConfigure(witf: cell, at: indexPath)
        return cell!
    }
    
    func setConfigure(witf cell:TTFDCell?,at indexPath: IndexPath){
        cell?.separatorInset.right = 16;
        cell?.setModel = TTDateTool.share.cellDataArr?[indexPath.row]
    }
    
    
    func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
        
        return 160;
    }
}

extension TTMJTestVC:UITableViewDelegate{
    func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
        
        
    }
}

©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • Android 自定义View的各种姿势1 Activity的显示之ViewRootImpl详解 Activity...
    passiontim阅读 174,029评论 25 709
  • 昨天文章中,提到需求体系化可能涉及的三个用户。今天便聊聊第一个用户BA,BA一般会在进行需求分析,尤其是需求实例化...
    玉露君阅读 720评论 0 0
  • 黄金思维圈是迅速看透问题本质的利器 在我们生活当中,我们会学到很多的思考工具和方法,但对我而言,印象最深影响最大的...
    奔向自由的路上阅读 431评论 1 1
  • 果然上天是公平的,这里的一天也并没有比家乡长久太多。 生活也很舒适,借着学习的理由在临时分给我的小屋里一待一天。小...
    丶行烟阅读 292评论 0 2
  • 马上就大三了,同学们也开始了职业焦虑。考研?考公务员?还是自己闯天下? 在面对未来的不确定时,我希望大...
    伍月不会下雪阅读 143评论 0 0