Elastic pull to refresh for iOS developed in Swift

Overview

DGElasticPullToRefresh

Elastic pull to refresh compontent developed in Swift

Inspired by this Dribbble post: Pull Down to Refresh by Hoang Nguyen

Tutorial on how this bounce effect was achieved can be found here.

Requirements

  • Xcode 7 or higher
  • iOS 8.0 or higher (may work on previous versions, just did not test it)
  • ARC
  • Swift 3.0

Demo

Open and run the DGElasticPullToRefreshExample project in Xcode to see DGElasticPullToRefresh in action.

Installation

CocoaPods

pod 'DGElasticPullToRefresh'

Manual

Add DGElasticPullToRefresh folder into your project.

Example usage

// Initialize tableView
let loadingView = DGElasticPullToRefreshLoadingViewCircle()
loadingView.tintColor = UIColor(red: 78/255.0, green: 221/255.0, blue: 200/255.0, alpha: 1.0)
tableView.dg_addPullToRefreshWithActionHandler({ [weak self] () -> Void in
    // Add your logic here
    // Do not forget to call dg_stopLoading() at the end
    self?.tableView.dg_stopLoading()
}, loadingView: loadingView)
tableView.dg_setPullToRefreshFillColor(UIColor(red: 57/255.0, green: 67/255.0, blue: 89/255.0, alpha: 1.0))
tableView.dg_setPullToRefreshBackgroundColor(tableView.backgroundColor!)

Do not forget to remove pull to refresh on view controller deinit. It is a temporary solution.

deinit {
    tableView.dg_removePullToRefresh()
}

Description

Add pull to refresh without loading view:

func dg_addPullToRefreshWithActionHandler(_ actionHandler: @escaping () -> Void)

Add pull to refresh with loading view:

func dg_addPullToRefreshWithActionHandler(_ actionHandler: @escaping () -> Void, loadingView: DGElasticPullToRefreshLoadingView?)

You can use built-in DGElasticPullToRefreshLoadingViewCircle or create your own by subclassing DGElasticPullToRefreshLoadingView and implementing these methods:

func setPullProgress(_ progress: CGFloat)
func startAnimating()
func stopLoading()

Remove pull to refresh:

func dg_removePullToRefresh()

Set auto start loading:

func dg_startLoading()

Change pull to refresh background color:

func dg_setPullToRefreshBackgroundColor(_ color: UIColor)

Change pull to refresh fill color:

func dg_setPullToRefreshFillColor(_ color: UIColor)

Contribution

Please feel free to submit pull requests. Cannot wait to see your custom loading views for this pull to refresh.

Contact

Danil Gontovnik

License

The MIT License (MIT)

Copyright (c) 2015 Danil Gontovnik

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Comments
  • DGElasticPullToRefreshLoadingViewCircle not public

    DGElasticPullToRefreshLoadingViewCircle not public

    DGElasticPullToRefreshLoadingViewCircle is not public and is not accessible when using DGE as a framework (CocoaPods).

    Also, please consider renaming the classes to have shorter names. Swift has namespaces, so no need to obj-c style long names and prefixes.

    opened by tapz 16
  • Error When do the refresh and press back

    Error When do the refresh and press back

    Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'An instance 0x12e95fc00 of class UITableView was deallocated while key value observers were still registered with it. Current observation info: <NSKeyValueObservationInfo 0x12fc63f10> ( <NSKeyValueObservance 0x12fc34920: Observer: 0x12fc5ada0, Key path: contentOffset, Options: <New: YES, Old: NO, Prior: NO> Context: 0x0, Property: 0x12f915730> )'

    already did the de init :(

    opened by shanmarkus 6
  • After pulling to refresh, a line appears under the Navigation bar

    After pulling to refresh, a line appears under the Navigation bar

    After pulling to refresh, a line appears under the Navigation bar until refresh has finished. Can you point our where in the library this might be occurring?

    Im setting an image as the background self.navigationController!.navigationBar.setBackgroundImage(...) And hiding the shadow with this self.navigationController!.navigationBar.shadowImage = UIImage()

    pulling

    loading

    opened by fraserscottmorrison 5
  • Goes under UINavigation Bar

    Goes under UINavigation Bar

    makes the tableView go under the UINavigation bar.

    Here is the code I used to set up the pull to refresh.

    // Initialize tableView let loadingView = DGElasticPullToRefreshLoadingViewCircle() loadingView.tintColor = UIColor.whiteColor() tableView.dg_addPullToRefreshWithActionHandler({ weak self -> Void in self!.loadData() }, loadingView: loadingView) tableView.dg_setPullToRefreshFillColor(UIColor(red:0.000000, green:0.764706, blue:0.235294, alpha:1.0)) tableView.dg_setPullToRefreshBackgroundColor(tableView.backgroundColor!)

    image

    image

    opened by DawsonSeibold 4
  • UITableView flicker

    UITableView flicker

    Experiencing bug on iPhoneX only. Cannot reproduce in simulator. When I let go of pull, the tableView quickly snaps to the top of the view and then readjusts to proper position under navigation bar.

    opened by aamahdwalker 3
  • Not working on Xcode 8 / Swift 3

    Not working on Xcode 8 / Swift 3

    I installed DGElasticPullToRefresh using cocoapod. So I have version (1.0.3). It does not build : I have 30 errors.

    Is swift 3 support planned ?

    Many thanks

    opened by mobilityvalley 3
  • Refreshing makes the UITableView disappear

    Refreshing makes the UITableView disappear

    Hello,

    The animation looks amazing but I can't get it to work. This is my code:

    let loadingView = DGElasticPullToRefreshLoadingViewCircle()
    loadingView.tintColor = UIColor.whiteColor()
    tableView.dg_addPullToRefreshWithActionHandler({ [weak self] in
            dispatch_after(dispatch_time(DISPATCH_TIME_NOW, Int64(1.5 * Double(NSEC_PER_SEC))), dispatch_get_main_queue(), {
                self?.tableView.dg_stopLoading()
            })
            }, loadingView: loadingView)
    tableView.dg_setPullToRefreshFillColor(UIColor().menuDarkBlueColor())
    tableView.dg_setPullToRefreshBackgroundColor(view.backgroundColor!)
    

    Even if I remove the dispatch_after, as soon as I release the UIScrollView of the tableView, it completely disappears from the hierarchy. As you can see from these screenshots, the UITableView is removed from the hierarchy. Could this be due to a bug in your library? The first screenshot is before reloading, the second one is while the pull to refresh animation is in course and the last is when the UIScrollView is released. You can find my source code here: https://github.com/BalestraPatrick/Tweetometer First screen shot 2016-02-10 at 8 54 36 pm Second screen shot 2016-02-10 at 8 54 52 pm Third screen shot 2016-02-10 at 8 55 02 pm

    duplicate 
    opened by BalestraPatrick 3
  • DGElasticPullToRefresh in Objective-C

    DGElasticPullToRefresh in Objective-C

    I wrote a version for DGElasticPullToRefresh in Objective-C,but is imperfect , need your help link :https://github.com/Mainstayz/DGElasticPullToRefresh 😊

    opened by Mainstayz 3
  • Loading view snaps underneath navigation bar

    Loading view snaps underneath navigation bar

    For some reason, the view is snapping underneath my navigation bar? I have used the demo code given in the ReadMe.

    // Initialize tableView
    let loadingView = DGElasticPullToRefreshLoadingViewCircle()
    loadingView.tintColor = UIColor(red: 78/255.0, green: 221/255.0, blue: 200/255.0, alpha: 1.0)
    tableView.dg_addPullToRefreshWithActionHandler({ [weak self] () -> Void in
        // Add your logic here
        // Do not forget to call dg_stopLoading() at the end 
        self?.tableView.dg_stopLoading()
    }, loadingView: loadingView)
    tableView.dg_setPullToRefreshFillColor(UIColor(red: 57/255.0, green: 67/255.0, blue: 89/255.0, alpha: 1.0))
    tableView.dg_setPullToRefreshBackgroundColor(tableView.backgroundColor!)
    

    Video below..

    giphy

    opened by ZacharyKhan 2
  • Crash if the table view is removed before animation completes

    Crash if the table view is removed before animation completes

    Need to add

    if (!self.observing) { return } 
    

    in animateBounce() -> UIView.animateWithDuration -> completion:

    or it will cause crash if the tableview is removed before it's called.

    bug 
    opened by joe528 2
  • UITableViews set via IBOutlets from xib, with tableHeaderView disappear after refresh

    UITableViews set via IBOutlets from xib, with tableHeaderView disappear after refresh

    If a UITableView is set in a xib file and hooked unto the view controller via an IBOutlet, and it includes a tableHeaderView, it disappears after a pull to refresh.

    This will be because the IBOutlet only has a weak reference to the UITableView and it is removed from the view heirachy temporarily

    This is where is occurs:

    public extension UIScrollView {
        func dg_stopScrollingAnimation() {
            if let superview = self.superview, let index = superview.subviews.indexOf({ $0 == self }) as Int! {
                let strongSelf = self
                //removeFromSuperview() // commenting out this line fixes the issue, but Im not sure if its needed for something else (changing the index?)
                superview.insertSubview(strongSelf, atIndex: index)
            }
        }
    }
    
    opened by fraserscottmorrison 2
  • Wrong position of the pullToRefreshView

    Wrong position of the pullToRefreshView

    @gontovnik Thank you for making this nice control.

    I used this nice control to our application to pull refresh the data on the UICollectionView. But I am facing with a problem when I set contentInset of the collectionView to any values. Hereunder is my code:

    `colView.contentInset = UIEdgeInsets(top: 0, left: 50, bottom: 0, right: 50)

        let loadingView = DGElasticPullToRefreshLoadingViewCircle()
        loadingView.tintColor = .red
        colView.dg_addPullToRefreshWithActionHandler({ [weak self] in
            self?.delay(3, closure: {
                self?.colView.dg_stopLoading()
            })
            }, loadingView: loadingView)
        colView.dg_setPullToRefreshFillColor(.blue)
        colView.dg_setPullToRefreshBackgroundColor(.red)`
    

    The problem is the X position of the pullToRefreshView start at the contentInset 50 but it end of the screen. Simulator Screen Shot - iPhone XS Max - 2019-08-29 at 22 39 08

    My expectation to have the pullToRefreshView starts at the beginning of the screen instead.

    Anyone else have the same issue? Could you please tell me how to fix this?

    Thanks!

    opened by anphanngocvn 1
Releases(1.1)
A pull-down-to-refresh control for iOS that plays pong, originally created for the MHacks III iOS app

BOZPongRefreshControl A pull-down-to-refresh control for iOS that plays pong Installation It's on CocoaPods! Put pod 'BOZPongRefreshControl' in your P

Ben Oztalay 885 Dec 12, 2022
✳️ SwiftUI Pull to Refresh (for iOS 13 and iOS 14) package.

Refreshable ✳️ SwiftUI Pull to Refresh (for iOS 13 and iOS 14) package. See complementary article at SwiftUI Pull to Refresh (for iOS 13 and iOS 14).

Geri Borbás 21 Dec 2, 2022
Fully customizable pull-to-refresh control inspired by Storehouse iOS app

CBStoreHouseRefreshControl What is it? A fully customizable pull-to-refresh control for iOS inspired by Storehouse iOS app ![screenshot1] (https://s3.

Suyu Zhang 4k Jan 6, 2023
Animated, customizable, and flexible pull-to-refresh framework for faster and easier iOS development.

KafkaRefresh Animated, customizable, and flexible pull-to-refresh framework for faster and easier iOS development. Report bug · Request feature · 中文文档

H. H. Hsiang 1.2k Dec 11, 2022
Customizable pull-to-refresh control,written in pure Swift.

What is it This project is heavily inspired by CBStoreHouseRefreshControl which is Objective-C implemented. SurfingRefreshControl provides you a chanc

Peiwei 55 Aug 21, 2022
Pull-to-refresh animation in UICollectionView with a sticky header flow layout, written in Swift :large_orange_diamond:

ReplaceAnimation Implementation of Zee Young's Dribbble animation (https://dribbble.com/shots/2067564-Replace) Info I really liked Zee Young's animati

Alex Türk 957 Sep 13, 2022
Pull to refresh functionality for any ScrollView in SwiftUI!

SwiftUIPullToRefresh Pull to refresh is a common UI pattern, supported in UIKit via UIRefreshControl. (Un)surprisingly, it's also unavailable in Swift

Gordan Glavaš 185 Dec 29, 2022
Animated "Pull To Refresh" Library for UIScrollView.

PullToBounce Animated "Pull To Refresh" Library for UIScrollView. You can add animated "pull to refresh" action to your UIScrollView, UITableView and

Takuya Okamoto 1.9k Dec 5, 2022
Give pull-to-refresh & infinite scrolling to any UIScrollView with 1 line of code.

SVPullToRefresh + SVInfiniteScrolling These UIScrollView categories makes it super easy to add pull-to-refresh and infinite scrolling fonctionalities

Sam Vermette 4.9k Dec 1, 2022
One gesture, many actions. An evolution of Pull to Refresh.

MNTPullToReact MNTPullToReact is an extended evolution of the famous Pull to Refresh interaction. The main idea comes from a unique question: can the

Mention 777 Nov 20, 2022
Play BreakOut while loading - A playable pull to refresh view using SpriteKit

BreakOutToRefresh Play BreakOut while loading - A playable pull to refresh view using SpriteKit BreakOutToRefresh uses SpriteKit to add a playable min

Dominik Hauser 2.5k Dec 29, 2022
An easy way to use pull-to-refresh.

MJRefresh An easy way to use pull-to-refresh ?? ✍??Release Notes: more details Contents New Features Dynamic i18n Switching SPM Supported Swift Chaini

M了个J 13.7k Jan 6, 2023
GIFRefreshControl is a pull to refresh that supports GIF images as track animations.

GIFRefreshControl GIFRefreshControl is a pull to refresh that supports GIF images as track animations. Installation You have multiple choices here: Co

Kevin Delannoy 163 Oct 4, 2022
Custom animated pull-to-refresh that can be easily added to UIScrollView

PullToMakeSoup Custom animated pull-to-refresh that can be easily added to UIScrollView Check this article on our blog to know more details about anim

Yalantis 1.9k Dec 17, 2022
ESPullToRefresh is an easy-to-use component that give pull-to-refresh and infinite-scrolling implemention for developers.

ESPullToRefresh is an easy-to-use component that give pull-to-refresh and infinite-scrolling implemention for developers.

Vincent Li 1.7k Jan 8, 2023
An easy way to use pull-to-refresh

CRRefresh an easy way to use pull-to-refresh, If you want to customize its UI style, you just need conform the specified protocol. We will not regular

CRAnimation 957 Dec 13, 2022
PullToRefreshSwiftUI - Pull to refresh for SwiftUI

PullToRefreshSwiftUI Pull to refresh for SwiftUI. Usage with @State import Swift

Dmitry Kononchuk 1 Feb 28, 2022
LCPullRefresh - Use UIActivityIndicatorView to provide a pull-to-refresh function for UIScrollView.

LCPullRefresh Use UIActivityIndicatorView to provide a pull-to-refresh function for UIScrollView. Requirements iOS 8.0+ Xcode 11.0+ Usage Pull-up refr

LiuChang 7 Aug 5, 2022
Simple refresh control for iOS based on SpriteKit and Core Graphics

RainyRefreshControl Simple refresh control for iOS based on SpriteKit and Core Graphics. Project inspired by concept of Yup Nguyen Installation Instal

Onix-Systems 680 Dec 29, 2022