Giter Site home page Giter Site logo

benuuu / icspulltorefresh.swift Goto Github PK

View Code? Open in Web Editor NEW

This project forked from icodesign/icspulltorefresh.swift

0.0 1.0 0.0 39 KB

Pure Swift PullToRefresh, providing PullToRefresh && InfiniteScrolling features for UIScrollView

License: MIT License

Ruby 2.40% Swift 95.26% Objective-C 2.35%

icspulltorefresh.swift's Introduction

ICSPullToRefresh-Swift MIT License

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.

CocoaPods

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.4'

Carthage

To integrate ICSPullToRefresh into your Xcode project using Carthage, specify it in your Cartfile:

github "iCodesign/ICSPullToRefresh" >= 0.4

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.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.