The Swift version uses the Thpullrefresh implementation Drop-down pull up Refresh data _swift

Source: Internet
Author: User
Tags closure

Recently I wrote a drop-down load latest, pull load more refresh control. Learn from other excellent open source code implementation effects such as Mjrefresh and Dgelasticpullrefresh. The main purpose is to learn the good ideas of others.

How to use:

Cocoapods import: Pod ' Thpullrefresh ',

Import ' Thpullrefresh ' in the project

Manual import: Drag all files in the ' Thpullrefresh ' folder into the project

The addition of the basic effect of head and foot

The specific code is as follows:

 override func Viewdidload () {super.viewdidload () Self.tableView.registerClass (Uitableviewcell.classforcoder (), Forcellreuseidentifier: "Tableviewcell") Self.tableView.rowHeight =    Uitableviewautomaticdimension self.tableView.estimatedRowHeight = Self.tableView.tableFooterView = UIView ()// Self.tableView.addHeadRefresh (self) {()-> () in//Self.loadnewdata ()//} Self.tableView.addHeadRefre SH (Self, Action: "Loadnewdata") Self.tableView.head? Hidetimelabel=true Self.tableView.addFootRefresh (Self, Action: "Loadmoredata")} func Loadnewdata () {//delay mode  Quasi-Refresh Self.index = 0 delaytime (2.0, Closure: {()-> () in Self.dataArr.removeAllObjects () for (Var i = 0 i<5;i++) {Let str = "Newest 5 cell, self.index++" Self.dataArr.addObject (str)} self.t Ableview.reloaddata () Self.tableview. tableheadstoprefreshing ()})} 

Delaytime is a macro of a method

Func Delaytime (x:double,closure: ()-> ()) {Dispatch_after (Dispatch_time, Dispatch_time_now (
x * Double ( NSEC_PER_SEC))), Dispatch_get_main_queue (), closure)
}

To achieve the jelly effect

The code is as follows

Several colored dots can be ignored, which are developed to tune Bezier curves.


  /* *bgcolor background color
  *loadingcolor loaded color
  /public
  func Addbounceheadrefresh (target:anyobject?,bgcolor : Uicolor,loadingcolor:uicolor,action:selector);
 
Implement
the following Self.tableView.addBounceHeadRefresh (Self,bgcolor:uicolor.orangecolor (), Loadingcolor: Uicolor.bluecolor (), Action: "Loadnewdata")

Stop head refresh and bottom Refresh

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

The above is the entire content of this article, I hope to help you learn.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.