DEPRECATED: Pull to refresh in Swift
This library is no longer maintained. I am not using it in any of my projects, and I, unfortunately, don't have time to maintain it in my free time. Please open an issue if you are willing to become the new maintainer.
Refresher is pull to refresh library written in Swift. It provides easy to use UIScrollView methods to add pull to refresh to your view. Refresher also supports custom animations.
tableView.addPullToRefreshWithAction {
NSOperationQueue().addOperationWithBlock {
sleep(2)
NSOperationQueue.mainQueue().addOperationWithBlock {
self.tableView.stopPullToRefresh()
}
}
}
Refresher supports custom animations on PullToRefreshView
. You need to create object that conforms to PullToRefreshViewAnimator
protocol.
Then, just pass your custom animator in addPullToRefrshWithAction
:
tableView.addPullToRefreshWithAction({
NSOperationQueue().addOperationWithBlock {
sleep(2)
NSOperationQueue.mainQueue().addOperationWithBlock {
self.tableView.stopPullToRefresh()
}
}
}, withAnimator: CustomAnimator())
Required methods that your custom object need to implement are:
func pullToRefreshAnimationDidStart(view: PullToRefreshView)
- Called when user releases finger and when loading actually starts. Start your animations here.func pullToRefreshAnimationDidEnd(view: PullToRefreshView)
- Called when animation is over. Perform any necessary after animation cleanup here.func pullToRefresh(view: PullToRefreshView, progressDidChange progress: CGFloat)
- Called while user is pulling scroll view. Useful if you want to implement some kind of progress like behaviour.func pullToRefresh(view: PullToRefreshView, stateDidChange state: PullToRefreshViewState)
- Called when PullToRefreshView
changes its stateYou can use your own custom UIView
subclass as pull to refresh view.
if let customSubview = NSBundle.mainBundle().loadNibNamed("CustomSubview", owner: self, options: nil).first as? CustomSubview {
tableView.addPullToRefreshWithAction({
NSOperationQueue().addOperationWithBlock {
sleep(2)
NSOperationQueue.mainQueue().addOperationWithBlock {
self.tableView.stopPullToRefresh()
}
}
}, withAnimator: customSubview)
}
Your custom subclass has to conform to PullToRefreshViewDelegate
.
PullToRefresh.xcodeproj
and drag it into the file navigator of your app project.Refresher.framework
Refresher.framework
under "Products" group.Refresher.framework
to your projectpod 'Refresher'
to your Podfilepod install
Refresher is created by Josip Ćavar and inspired by SVPullToRefresh. If you have suggestions or bug reports, feel free to send pull request or create new issue.