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.