Swift版使用ThPullRefresh實現下拉上拉重新整理資料_Swift

來源:互聯網
上載者:User

最近自己寫了一個下拉載入最新,上拉載入更多的重新整理控制項。借鑒了其他優秀開原始碼的實現效果比如MJRefresh和DGElasticPullRefresh。主要是為了學習別人的優秀思想。

如何使用:

  Cocoapods 匯入:pod 'ThPullRefresh',

  在項目中 import 'ThPullRefresh'

  手動匯入:將'ThPullRefresh' 檔案夾中的所有檔案拽入項目中

   head與foot基本效果的添加  

具體代碼如下:

  override func viewDidLoad() {    super.viewDidLoad()    self.tableView.registerClass(UITableViewCell.classForCoder(), forCellReuseIdentifier: "tableViewCell")    self.tableView.rowHeight = UITableViewAutomaticDimension    self.tableView.estimatedRowHeight = 44    self.tableView.tableFooterView = UIView()//    self.tableView.addHeadRefresh(self) { () -> () in//      self.loadNewData()//    }    self.tableView.addHeadRefresh(self, action: "loadNewData")     self.tableView.head?.hideTimeLabel=true    self.tableView.addFootRefresh(self, action: "loadMoreData")  }    func loadNewData(){    //延時類比重新整理    self.index = 0    DeLayTime(2.0, closure: { () -> () in      self.dataArr.removeAllObjects()      for (var i = 0 ;i<5;i++){        let str = "最新5個cell,第\(self.index++)個"        self.dataArr.addObject(str)      }      self.tableView.reloadData()      self.tableView .tableHeadStopRefreshing()    })       }

DelayTime是一個方法的宏

func DeLayTime(x:Double,closure:()->()){dispatch_after(dispatch_time(DISPATCH_TIME_NOW, Int64(x * Double(NSEC_PER_SEC))), dispatch_get_main_queue(), closure)}

要實現果凍效果

 

代碼如下

幾個有顏色的點可以忽略,那是開發用於調貝茲路徑的。

  /*  *bgColor 背景顏色  *loadingColor 載入的顏色  */  public func addBounceHeadRefresh(target:AnyObject?,bgColor:UIColor,loadingColor:UIColor,action : Selector); //實現如下self.tableView.addBounceHeadRefresh(self,bgColor:UIColor.orangeColor(),loadingColor:UIColor.blueColor(), action: "loadNewData")

 停止頭部重新整理和底部重新整理

self.tableView.tableHeadStopRefreshing()self.tableView.tableFootStopRefreshing

以上就是本文的全部內容,希望對大家的學習有所協助。

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.