Giter VIP home page Giter VIP logo

dgelasticpulltorefresh's Introduction

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.

dgelasticpulltorefresh's People

Contributors

codeeagle avatar danielchristopher1 avatar gontovnik avatar haawa799 avatar lfarah avatar readmecritic avatar snakecharmer 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  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  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

dgelasticpulltorefresh's Issues

DGElasticPullToRefresh sometimes stays on screen until scroll

Steps to reproduce:

  1. Fire pull to refresh
  2. Quickly go to some detail view controller
  3. Quickly go back

Effect:
Pull to refresh sometimes stays on screen in some kind of hung state (circle not animating, view half cut). Scrolling the view removes the glitch from screen immediately

Expected effect:
View controller should appear in normal state with pull to refresh either hidden or finishing the animation gracefully.

Any advice on that or is it a bug that needs to be fixed?

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

request server

hi
I'm on a server with a lot of data is an array. I want whenever I applied for twenty data show in table view can i use plugin ??

No work in CollectionView

Hi, it is a beautiful refresh library, easy create in table
But it has a problem in Collection,can't drag to show ,but had run the function
scrollViewDidChangeContentOffset(dragging: false)

as below the code

 let loadingView = DGElasticPullToRefreshLoadingViewCircle()
        loadingView.tintColor = UIColor(red: 78/255.0, green: 221/255.0, blue: 200/255.0, alpha: 1.0)
        self.collectionView!.dg_addPullToRefreshWithActionHandler({ 
            DispatchQueue.main.asyncAfter(deadline: DispatchTime.now() + Double(Int64(1.5 * Double(NSEC_PER_SEC))) / Double(NSEC_PER_SEC), execute: {
                self.collectionView!.dg_stopLoading()
            })
        }, loadingView: loadingView)
        
        self.collectionView!.dg_setPullToRefreshFillColor(UIColor(red: 57/255.0, green: 67/255.0, blue: 89/255.0, alpha: 1.0))
     
        self.collectionView!.dg_setPullToRefreshBackgroundColor(self.collectionView!.backgroundColor!)

that was test in the demo example code
Thank you

TableView via Storyboard?

When I add this to a tableview in loadView (or viewDidLoad) from a storyboard, the tableview disappears after pulling to refresh. The code is called in the action block, but the tableview no longer is shown. View Debugging doesn't show the tableview in the hierarchy.

Anyone else have this issue?

Version 7.1.1 (7B1005)

A problem。

I have a problem, A present B, B dismiss, but B was not destroyed.
I think Dg_removePullToRefresh should not be called in deinit,
Because only call Dg_removePullToRefresh,B will be destroyed。
I modified the dg_removePullToRefresh。
public func dg_removePullToRefresh() { self.pullToRefreshView?.disassociateDisplayLink() self.pullToRefreshView?.observing = false self.pullToRefreshView?.removeFromSuperview() if self.pullToRefreshView != nil { self.pullToRefreshView = nil; } }
Google translation。

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

Wrong controlPoint positions after device rotation while refreshing

  1. Run example app
  2. Pull down to refresh
  3. When state is animatingBounce rotate device/simulator

Actual result:
Activity indicator view has invalid position as well as controlPoints positions
simulator screen shot oct 4 2016 22 56 53

Expected result:
I guess desired behaviour would be: finish/skip animatingBounce animation and go straight to loading state after rotation.

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

Unable to simultaneously satisfy constraints

Hey, I try to use it whit the storyboard, but when I pull down the table view, the tableView goes away.
Probably, because I use a tableView in Storyboard with constraints..
I don't know if you know what i meen :)

Using Storyboard

Hi,

I use storyboard but pull to refresh feature doesnt work properly. Circle animation not working, it stop immediately, and table view invisable.

My code here:

` //myTableView = UITableView(frame: ucretsizMaclarTableView.frame, style: .Plain) // This line caused error. (FlexibleWidh & Flexible Height, nil error)
myTableView.autoresizingMask = [.FlexibleWidth, .FlexibleHeight]

    let loadingView = DGElasticPullToRefreshLoadingViewCircle()
    loadingView.tintColor = UIColor(red: 78/255.0, green: 221/255.0, blue: 200/255.0, alpha: 1.0)
    myTableView.dg_addPullToRefreshWithActionHandler({ [weak self] () -> Void in
        dispatch_after(dispatch_time(DISPATCH_TIME_NOW, Int64(10 * Double(NSEC_PER_SEC))), dispatch_get_main_queue(), {
            self?.myTableView.dg_stopLoading()
        })
        }, loadingView: loadingView)
    myTableView.dg_setPullToRefreshFillColor(UIColor(red: 57/255.0, green: 67/255.0, blue: 89/255.0, alpha: 1.0))
    myTableView.dg_setPullToRefreshBackgroundColor(ucretsizMaclarTableView.backgroundColor!)`

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.

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 :(

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

Swift Selector Warning

That should be an easy fix.

▸ ⚠️  /Pods/DGElasticPullToRefresh/DGElasticPullToRefresh/DGElasticPullToRefreshView.swift:126:61: use '#selector' instead of explicitly constructing a 'Selector'
▸ displayLink = CADisplayLink(target: self, selector: Selector("displayLinkTick"))
▸                                                             ^~~~~~~~~~~~~~~~~~~~~~~~~~~
▸ ⚠️  /Pods/DGElasticPullToRefresh/DGElasticPullToRefresh/DGElasticPullToRefreshView.swift:144:74: use '#selector' instead of explicitly constructing a 'Selector'
▸ NSNotificationCenter.defaultCenter().addObserver(self, selector: Selector("applicationWillEnterForeground"), name: UIApplicationWillEnterForegroundNotification, object: nil)
▸                                                                          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
▸ Compiling DGElasticPullToRefreshConstants.swift
▸ Compiling DGElasticPullToRefreshExtensions.swift
▸ Compiling DGElasticPullToRefreshLoadingView.swift
▸ Compiling DGElasticPullToRefreshLoadingViewCircle.swift
▸ Compiling DGElasticPullToRefreshView.swift
▸ ⚠️  /Pods/DGElasticPullToRefresh/DGElasticPullToRefresh/DGElasticPullToRefreshView.swift:126:61: use '#selector' instead of explicitly constructing a 'Selector'
▸ displayLink = CADisplayLink(target: self, selector: Selector("displayLinkTick"))
▸                                                             ^~~~~~~~~~~~~~~~~~~~~~~~~~~
▸ ⚠️  /Pods/DGElasticPullToRefresh/DGElasticPullToRefresh/DGElasticPullToRefreshView.swift:144:74: use '#selector' instead of explicitly constructing a 'Selector'
▸ NSNotificationCenter.defaultCenter().addObserver(self, selector: Selector("applicationWillEnterForeground"), name: UIApplicationWillEnterForegroundNotification, object: nil)

1 pixel line between refresh view and collection view

Hi,

A one-pixel line appears at the moment when when releasing - as can be seen in the attached image. It flashes for the briefest moment in time, but my app's contrast between the two colours is very high so it's quite obvious.

Is this in the library or could it be something weird in the way my UI is put together?

screen shot 2017-07-30 at 20 30 17

Support UICollectionView

Hello,

I really want to use this library but I just want to know will it be compatible with UICollectionView?

Thank you! ;)

Deallocated while observers still registered

Hey !

I am trying to use your beautiful component but I am facing an error I can't solve. One of my view controller uses your DGElasticPullToRefreshwith its circle loading view. But when this view controller is deallocated I got the error :

Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'An instance 0x7fd7d4343080 of class UIScrollViewPanGestureRecognizer was deallocated while key value observers were still registered with it

Any idea how to solve this ?

Thanks

Not Working on swift 2.3

Unfortunately the project doesn't build on 2.3

in dg_center:

> if usePresentationLayerIfPossible,
>             let presentationLayer = layer.presentationLayer() as? CALayer {
>             // Position can be used as a center, because anchorPoint is (0.5, 0.5)
>             return presentationLayer.position
>         }
>         return center

returns the following error:
Downcast from 'CALayer?' to 'CALayer' only unwraps optionals; did you mean to use '!'?

I am not sure why that downcast is there as layer.presentationlayer() seems to return a CALayer. If its unneeded then removing the downcast allows the project to build

MinOffsetToPull for compact height

Smaller devices (i.e. iPhones, especially 5s) in landscape barely give enough height to pull to refresh.

I changed the MinOffsetToPull constant to 50 to be suitable for all devices, but it might be preferable to have it dynamic.

What are your thoughts on this value?

Wrong width when sectionIndex (alphabet scroll) enabled

When I pull to refresh and have section index enabled, on the pull and drag, the refreshView width gets cut off where the sectionIndex starts. On release, during the circle animation, the refreshView fills the entire width as it should.

I believe this is due to how Apple sets the active width of the scrollView when section Index is enabled, and since this library extends UIScrollView, it acts based on how Apple implements the scrollView behaviour.

Is there any currently known way around this? I'm sure a hacky solution exists, but just wondering if this is something that the library is capable of implementing

Translucent = true and device rotation are not compatible

  1. In the example project: set navigationController?.navigationBar.isTranslucent = true
  2. Run app
  3. Pulldown to refresh
  4. Rotate device while refreshing (for any animatingBounce or loading states)

Actual result:
Refresh view disappears after table refresh and extra table content top inset is added so there is a empty space between nav bar and table content.

After rotation when dragging scroll down:
simulator screen shot oct 4 2016 22 56 15

Expected result:
The same result when isTranslucent = false

Is there quick workaround for that?

Faint line between DGElasticPullToRefresh and Nav Bar

When i pull to refresh, i see a faint line, probably the Nav Bar's border line. While on your display view example, there isn't any line separating the DGElasticPullToRefresh from the Navigation Bar. Thanks in advance :)

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

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

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.