ICSPullToRefresh-Swift is a Swift version of SVPullToRefresh, providing PullToRefresh && InfiniteScrolling features for UIScrollView
Embedded frameworks require a minimum deployment target of iOS 8.
CocoaPods (>= 0.36) adds supports for Swift and embedded frameworks.
Add pod 'ICSPullToRefresh'
to your Podfile
:
source 'https://github.com/CocoaPods/Specs.git'
platform :ios, '8.0'
use_frameworks!
pod 'ICSPullToRefresh', '~> 0.3'
To integrate ICSPullToRefresh
into your Xcode project using Carthage, specify it in your Cartfile
:
github "iCodesign/ICSPullToRefresh" >= 0.3
You can also integrate ICSPullToRefresh
directly with souce code. Clone the repo and copy ICSPullToRefresh.swift
and ICSInfiniteScrolling.swift
to your project.
UIScrollView.addPullToRefreshHandler(() -> ())
Start/Stop animating:
UIScrollView.pullToRefreshView?.startAnimating()
UIScrollView.pullToRefreshView?.stopAnimating()
Trigger manually:
UIScrollView.triggerPullToRefresh()
Hide pulltorefresh:
UIScrollView.setShowsPullToRefresh(Bool)
Since after iOS7, iOS brings
automaticallyAdjustsScrollViewInsets
toUISrollView
embedded in aUINavigationController
orUITabBarController
which changescontentInset
ofUISrollView
betweenviewDidLoad
nadviewDidAppear
, so you have to put theaddPullToRefreshHandler
in or afterviewDidAppear
Example:
tableView.addPullToRefreshHandler {
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), { () -> Void in
// do something in the background
dispatch_async(dispatch_get_main_queue(), { () -> Void in
self.tableView.pullToRefreshView?.stopAnimating()
})
})
}
UIScrollView.addInfiniteScrollingWithHandler(() -> ())
Start/Stop animating:
UIScrollView.infiniteScrollingView?.startAnimating()
UIScrollView.infiniteScrollingView?.stopAnimating()
Trigger manually:
UIScrollView.triggerInfiniteScrolling()
Hide infiniteScrolling:
UIScrollView.setShowsInfiniteScrolling(Bool)
Since after iOS7, iOS brings
automaticallyAdjustsScrollViewInsets
toUISrollView
embedded in aUINavigationController
orUITabBarController
which changescontentInset
ofUISrollView
betweenviewDidLoad
nadviewDidAppear
, so you have to put theaddInfiniteScrollingWithHandler
in or afterviewDidAppear
Example:
tableView.addInfiniteScrollingWithActionHandler {
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), { () -> Void in
// do something in the background
dispatch_async(dispatch_get_main_queue(), { [unowned self] in
self.tableView.reloadData()
self.tableView.infiniteScrollingView?.stopAnimating()
})
})
}
Thanks to SVPullToRefresh by Sam Vermette.