ICSPullToRefresh 0.6

ICSPullToRefresh 0.6

TestsTested
LangLanguage SwiftSwift
License MIT
ReleasedLast Release Nov 2016
SwiftSwift Version 3.0
SPMSupports SPM

Maintained by iCodesign.



  • By
  • iCodesign

ICSPullToRefresh-Swift

ICSPullToRefresh-Swift is a Swift version of SVPullToRefresh, providing PullToRefresh && InfiniteScrolling features for UIScrollView

Installation

Embedded frameworks require a minimum deployment target of iOS 8.

Manually

You can also integrate ICSPullToRefresh directly with souce code. Clone the repo and copy ICSPullToRefresh.swift and ICSInfiniteScrolling.swift to your project.

Usage

PullToRefresh

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 to UISrollView embedded in a UINavigationController or UITabBarController which changes contentInset of UISrollView between viewDidLoad nad viewDidAppear, so you have to put the addPullToRefreshHandler in or after viewDidAppear

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()
        })
    })
}

InfiniteScrolling

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 to UISrollView embedded in a UINavigationController or UITabBarController which changes contentInset of UISrollView between viewDidLoad nad viewDidAppear, so you have to put the addInfiniteScrollingWithHandler in or after viewDidAppear

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()
        })
    })
}

Credits

Thanks to SVPullToRefresh by Sam Vermette.