Giter Club home page Giter Club logo

pulltobounce's Introduction

PullToBounce

Platform Language License CocoaPods

Animated "Pull To Refresh" Library for UIScrollView.

You can add animated "pull to refresh" action to your UIScrollView, UITableView and UICollectionView.

Inspired by https://dribbble.com/shots/1797373-Pull-Down-To-Refresh

Objective-C version is here.

Xamarin.iOS version is here.

ScreenShot

Demo GIF Animation

You can play demo at appetize.io.

Installation

You can install this to your project via CocoaPods.

pod 'PullToBounce'

Usage

Please Wrap your scroll view

// Please wrap your scroll view
tableView.frame = yourFrame
let tableViewWrapper = PullToBounceWrapper(scrollView: tableView)

// Please add wrapper view to your view instead of your scroll view.
bodyView.addSubview(tableViewWrapper)

The frame of wrapper will be same as your scrollView.

And the color will be same as your scrollView's background color.

Event Handler

tableViewWrapper.didPullToRefresh = {
    didFinishYourLoading() {
        tableViewWrapper.stopLoadingAnimation()
    }
}

Custom Animation

Default arguments of "init" of PullToBounceWrapper

init(
  scrollView: UIScrollView, // this is the only required argument
  bounceDuration: CFTimeInterval = 0.8,
  ballSize:CGFloat = 36,
  ballMoveTimingFunc: CAMediaTimingFunction = CAMediaTimingFunction(controlPoints:0.49,0.13,0.29,1.61),
  moveUpDuration: CFTimeInterval = 0.25,
  pullDistance: CGFloat = 96,
  bendDistance: CGFloat = 40,
  didPullToRefresh: (()->())? = nil
)

You can use these arguments to customize animation.

pulltobounce's People

Contributors

kdvmgn avatar lyc2345 avatar mattleibow avatar ndlinh avatar ndlinh-celtic avatar schickling avatar takuoka 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

pulltobounce's Issues

What is the connection between `Screen size` and `bendDistance` on different devices?

There is my code :

let ballSize = self.view.bounds.size.width / 12
        _pullToBounce = PullToBounceWrapper(scrollView: _collectionView,
            bounceDuration: 0.8,  /
            ballSize: ballSize,  
            ballMoveTimingFunc: CAMediaTimingFunction(controlPoints:0.49,0.13,0.29,1.61),
            moveUpDuration: 0.25, 
            pullDistance: ballSize * 2, 
            bendDistance: ballSize * 1.8, 
            didPullToRefresh: {  
                // test
                NSTimer.schedule(delay: 6) {
                    [unowned self] timer in
                    self._pullToBounce?.stopLoadingAnimation()
                }
            })

The ballSize is related to Screen bound,
when i set bendDistance as benDistance * 1.8, the code works well on iPhone 6s but crashes on iPhone 5s, and then i set bendDistance as benDistance * 1.9 it crashes on iPhone 6s but works well on iPhone 5s.

What is the connection between Screen size and bendDistance on different devices?

autoLayout

when i used snp layout llike
`
func createTableview() -> Void {
let changeCityTableView = ChangeCityTableView()
self.view.addSubview(changeCityTableView)
changeCityTableView.snp.makeConstraints { (make) in
make.edges.equalToSuperview()
}

    let tableViewWrapper = PullToBounceWrapper(scrollView: changeCityTableView)
    self.view.addSubview(tableViewWrapper)

    tableViewWrapper.didPullToRefresh = {
        Timer.schedule(delay: 2) { timer in
            tableViewWrapper.stopLoadingAnimation()
        }
    }
}

`
a crash open
assert(false, "Wow, scrollView.frame is CGRectZero. Please set frame size.")

Update CocoaPod

I saw that you updated the repo to swift 3 however cocoa pods still has the swift 2 version. Could you please update the cocoa pod?

Problem integration to UITableViewController

Tried to apply this to a UITableViewController. Here are the codes:

override func viewDidLoad() {
super.viewDidLoad()

let bodyView = UIView()
bodyView.frame = self.view.frame
bodyView.frame.y += 20 + 44
self.view.addSubview(bodyView)

// pull to refresh usage
let tableViewWrapper = PullToBounceWrapper(scrollView: tableView)
bodyView.addSubview(tableViewWrapper)

tableViewWrapper.didPullToRefresh = {
  NSTimer.schedule(delay: 2) { timer in
    tableViewWrapper.stopLoadingAnimation()
  }
}

// createHeader()

}

Terminating app due to uncaught exception 'CALayerInvalid', reason: 'layer <CALayer: 0x7fd501f5dc60> is a part of cycle in its layer tree'. Anyone else have this issue?

Swift3

it'd be cool to have a swift 3 version, if you have any interest to create a branch i would like to help with that.

Can't implement this on Swift 4.2 xCode 10

I have tried to get this working in my project in Swift 4 but when i add the control, my scrollview content doesn't load and it just loads with a white view in the scrollview.

MY view hierarchy is as follows:
UIViewController -> View -> ScrollView -> 3x UIViews & 3x UICollectionViews

The scrollview is implemented via the storyboard with the layout constraints that is is aligned top, leading, trailing, bottom to the main view controller view.

I want to add the pull to refresh to my scrollview

I have done the following code, and tried variations but it doesn't work:

// Please wrap your scroll view
scrollView.frame = self.view.frame
let tableViewWrapper = PullToBounceWrapper(scrollView: scrollView)
// Please add wrapper view to your view instead of your scroll view.
self.view.addSubview(tableViewWrapper)

I've also tried creating a new UIview bodyview per your tutorial:
let bodyView = UIView()
bodyView.frame = scrollView.frame
let tableViewWrapper = PullToBounceWrapper(scrollView: scrollView)
bodyView.add(tableViewWrapper)
self.view.addSubview(bodyView)

I'm either missing something very simple, or something isn't working and would appreciate some guidance if you're able to!

Swift 2.0 syntax error

It seems that swift 2 does not accept the '#' syntax for the function arguments.

This can cause compiling error.

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.