ICSPullToRefresh-AnimatedImages is a Fork version of ICSPullToRefresh-Swift which adds the ability to use any series of images as the Activity Indicator for both Pull to Refresh and Infinite scrolling
Embedded frameworks require a minimum deployment target of iOS 8.
CocoaPods 0.36 adds supports for Swift and embedded frameworks.
Add pod 'ICSPullToRefresh-AnimatedImages'
to your Podfile
:
source 'https://github.com/CocoaPods/Specs.git'
platform :ios, '8.0'
use_frameworks!
pod 'ICSPullToRefresh', '~> 0.1.2'
You can also integrate ICSPullToRefresh-AnimatedImages
directly with souce code. Clone the repo and copy ICSPullToRefresh.swift
and ICSInfiniteScrolling.swift
to your project.
Adding images for activity indicator
UIScrollView.configurePullToRefreshAnimation(duration:NSTimeInterval, staticImage:UIImage, animationImages:[UIImage])
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.configurePullToRefreshAnimation(1.0, staticImage: UIImage(named: "Loading1")!, animationImages: [UIImage(named: "Loading0")!, UIImage(named: "Loading1")!, UIImage(named: "Loading2")!, UIImage(named: "Loading3")!, UIImage(named: "Loading4")!, UIImage(named: "Loading5")!, UIImage(named: "Loading6")!, UIImage(named: "Loading7")!])
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
tableView.pullToRefreshView?.stopAnimating()
})
})
}
Adding images for scroll activity indicator:
UIScrollView.configureInfiniteScrollingAnimation(duration:NSTimeInterval, staticImage:UIImage, animationImages:[UIImage])
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.configureInfiniteScrollingAnimation(1.0, staticImage: UIImage(named: "Loading1")!, animationImages: [UIImage(named: "Loading0")!, UIImage(named: "Loading1")!, UIImage(named: "Loading2")!, UIImage(named: "Loading3")!, UIImage(named: "Loading4")!, UIImage(named: "Loading5")!, UIImage(named: "Loading6")!, UIImage(named: "Loading7")!])
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 ICSPullToRefresh.Swift and SVPullToRefresh by Sam Vermette.