Giter Site home page Giter Site logo

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

Carthage

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

github "iCodesign/ICSPullToRefresh" >= 0.6

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), { [weak self] () -> 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), { [weak self] () -> 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.

icspulltorefresh.swift's People

Contributors

icodesign avatar jessearmand avatar krasnoukhov avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

icspulltorefresh.swift's Issues

infiniteScrollingView是否可以在接近底部的位置预先展示一个loading状态的indicator?

hello wanglei,

我发现目前的版本在下拉到尾部的时候给人的感觉不太友好,是否可以在接近尾部的时候预先加载一个loading状态的indicator?

另外顶部下拉的时候,如果在网速过快的时候是否可以人为的增加一点延迟时间,否则给人感觉是下拉无效,而且loading的菊花也不会转动(我不确定是不是我的网速太快了....)

谢谢~

Support for swift 3

I noticed that the last commit was march. Anyone has any experience with this pod with swift 3?

Xcode 7 problem

Hi, there is a problem with the Xcode 7 GM and Swift 2

   public override func observeValueForKeyPath(keyPath: String?, ofObject object: AnyObject?, change: [String : AnyObject]?, context: UnsafeMutablePointer<Void>) {
    if keyPath == observeKeyContentOffset {
        srollViewDidScroll(change[NSKeyValueChangeNewKey]?.CGPointValue)
    } else if keyPath == observeKeyFrame {
        setNeedsLayout()
    }
}

the error is: Cannot subscript a value of type '[String : AnyObject]?' with an index of type 'String'

Handler retain cycle

I recently ran into the issue that my view controller had a retain cycle in the pullToRefresh handler. I don't think that there needs something to be changed, but I do suggest that you add a [weak self] in your example as follows:

tableView.addPullToRefreshHandler { [weak self] in
    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()
        })
    })
}

Infinite scrolling does not working well

Hello,

Infinite scrolling is trigger when I just try to scroll tableview to see my last cell.
It should only trigger when Last cell + Some threshold

Help to solve this.

Thank you

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.