All Projects → Yalantis → Pulltorefresh

Yalantis / Pulltorefresh

Licence: mit
This component implements pure pull-to-refresh logic and you can use it for developing your own pull-to-refresh animations

Programming Languages

swift
15916 projects

Projects that are alternatives of or similar to Pulltorefresh

Pull To Refresh.rentals Ios
This project aims to provide a simple and customizable pull to refresh implementation. Made in Yalantis
Stars: ✭ 2,171 (+88.78%)
Mutual labels:  cocoapods, pull-to-refresh, yalantis
Adchromepulltorefresh
ADChromePullToRefresh
Stars: ✭ 263 (-77.13%)
Mutual labels:  cocoapods, pull-to-refresh
Segmentio
Animated top/bottom segmented control written in Swift.
Stars: ✭ 2,310 (+100.87%)
Mutual labels:  cocoapods, yalantis
Yalfield
Custom Field component with validation for creating easier form-like UI from interface builder.
Stars: ✭ 476 (-58.61%)
Mutual labels:  cocoapods, yalantis
Fittrack
Concept of a fitness app.
Stars: ✭ 165 (-85.65%)
Mutual labels:  cocoapods, yalantis
Displayswitcher
Custom transition between two collection view layouts
Stars: ✭ 2,253 (+95.91%)
Mutual labels:  cocoapods, yalantis
Guillotinemenu
Our Guillotine Menu Transitioning Animation implemented in Swift reminds a bit of a notorious killing machine.
Stars: ✭ 2,908 (+152.87%)
Mutual labels:  cocoapods, yalantis
Colormatchtabs
This is a Review posting app that let user find interesting places near them
Stars: ✭ 1,341 (+16.61%)
Mutual labels:  cocoapods, yalantis
Listplaceholder
ListPlaceholder is a swift library allows you to easily add facebook style animated loading placeholder to your tableviews or collection views.
Stars: ✭ 511 (-55.57%)
Mutual labels:  cocoapods, tableview
Pulltorefreshkit
【Deprecated】Pull to refresh in Swift, easy to use, easy to customize(下拉刷新/QQ/淘宝/优酷/雅虎天气/大众点评)
Stars: ✭ 533 (-53.65%)
Mutual labels:  tableview, pull-to-refresh
Koloda
KolodaView is a class designed to simplify the implementation of Tinder like cards on iOS.
Stars: ✭ 4,998 (+334.61%)
Mutual labels:  cocoapods, yalantis
Accordionswift
The best way of implement an accordion menu using an UITableView in Swift
Stars: ✭ 156 (-86.43%)
Mutual labels:  cocoapods, tableview
Abexpandableview
Expandable, collapsible, filterable and single/multi selectable table view.
Stars: ✭ 138 (-88%)
Mutual labels:  cocoapods, tableview
Parallaxheader
Simple way to add parallax header to UIScrollView/UITableView written in Swift.
Stars: ✭ 808 (-29.74%)
Mutual labels:  cocoapods, tableview
Luexpandabletableview
A subclass of UITableView with expandable and collapsible sections
Stars: ✭ 125 (-89.13%)
Mutual labels:  cocoapods, tableview
Containercontroller
UI Component. This is a copy swipe-panel from app: Apple Maps, Stocks. Swift version
Stars: ✭ 273 (-76.26%)
Mutual labels:  cocoapods, tableview
Pulltomakeflight
Custom animated pull-to-refresh that can be easily added to UIScrollView
Stars: ✭ 497 (-56.78%)
Mutual labels:  pull-to-refresh, yalantis
Forceblur
ForceBlur Animation for iOS Messaging Apps
Stars: ✭ 666 (-42.09%)
Mutual labels:  cocoapods, yalantis
Preloader.ophiuchus
Custom Label to apply animations on whole text or letters.
Stars: ✭ 880 (-23.48%)
Mutual labels:  cocoapods, yalantis
Threadly
Type-safe thread-local storage in Swift
Stars: ✭ 58 (-94.96%)
Mutual labels:  cocoapods

Customizable PullToRefresh

This component implements pure pull-to-refresh logic and you can use it for developing your own pull-to-refresh animations, like this one.

Yalantis

Requirements

  • iOS 8.0+
  • Swift 5.0 (v 3.2+)
  • Swift 4.2 (v 3.1+)
  • Swift 3 (v. 2.0+)
  • Swift 2 (v. 1.4)

Installing

with CocoaPods

use_frameworks!
pod 'PullToRefresher'

with Carthage

github "Yalantis/PullToRefresh"

Usage

At first, import PullToRefresh:

import PullToRefresh

The easiest way to create PullToRefresh:

let refresher = PullToRefresh()

It will create a default pull-to-refresh with a simple view which has single UIActivitiIndicatorView. To add refresher to your UIScrollView subclass:

tableView.addPullToRefresh(refresher) {
    // action to be performed (pull data from some source)
}

⚠️ Don't forget to remove pull to refresh when your view controller is releasing. ⚠️

deinit {
    tableView.removeAllPullToRefresh()
}

After the action is completed and you want to hide the refresher:

tableView.endRefreshing()

You can also start refreshing programmatically:

tableView.startRefreshing()

But you probably won’t use this component, though. UITableViewController and UICollectionViewController already have a simple type of refresher. It’s much more interesting to develop your own pull-to-refresh control.

Usage in UITableView with sections

Unfortunaly, UITableView with sections currently not supported. But you can resolve this problem in two steps:

  1. Create you own PullToRefresh (see instructions below).
  2. Set its shouldBeVisibleWhileScrolling property to true. It makes you PullToRefresh always visible while you're scrolling the table.

⚠️ By default PullToRefresh has transparent background which leads to unwanted overlapping behavour. ⚠️

Disable/Enable

You can disable/enable refresher in runtime:

yourRefresher.setEnable(isEnabled: false)

Creating custom PullToRefresh

To create a custom refresher you would need to initialize PullToRefresh class with two objects:

  • refreshView is a UIView object which will added to your scroll view;
  • animator is an object which will animate elements on refreshView depending on the state of PullToRefresh.
let awesomeRefresher = PullToRefresh(refresherView: yourView, animator: yourAnimator)

Steps for creating custom PullToRefresh

  1. Create a custom UIView with *.xib and add all images that you want to animate as subviews. Pin them with outlets:
class RefreshView: UIView {

    @IBOutlet private var imageView: UIImageView!
  
    // and others
}
  1. Create an Animator object that conforms RefreshViewAnimator protocol and can be initialized by your custom view:
class Animator: RefreshViewAnimator {

    private let refreshView: RefreshView
    
    init(refreshView: RefreshView) {
        self.refreshView = refreshView
    }

    func animate(state: State) {
        // animate refreshView according to state
    }
}
  1. According to RefreshViewAnimator protocol, your animator should implement animateState method. This method is get called by PullToRefresh object every time its state is changed. There are four states:
public enum State: Equatable, CustomStringConvertible {
    
    case initial
    case releasing(progress: CGFloat)
    case loading
    case finished
}
  • Initial - refresher is ready to be pulled.
  • Releasing - refresher is in the process of releasing (by a user or programmatically). This state contains a double value which represents releasing progress from 0 to 1.
  • Loading - refresher is in the loading state.
  • Finished - loading is finished.

Depending on the state that your animator gets from the PullToRefresh, it has to animate elements in refreshView:

func animate(state: State) {
    switch state {
      case .initial: // do inital layout for elements
      case .releasing(let progress): // animate elements according to progress
      case .loading: // start loading animations
      case .finished: // show some finished state if needed
    }
}

Place the magic of animations insted of commented lines.

  1. For the convitience sake you can sublass from PullToRefresh and create separate class for your refresher:
class AwesomePullToRefresh: PullToRefresh {

    convenience init() {
        let refreshView = Bundle(for: type(of: self)).loadNibNamed("RefreshView", owner: nil, options: nil)!.first as! RefreshView
        let animator = Animator(refreshView: refreshView)
        self.init(refreshView: refreshView, animator: animator)
    }
}
  1. Finally, add a refresher to a UIScrollView subclass:
tableView.addPullToRefresh(refresher) {
    // action to be performed (pull data from some source)
}

Have fun! :)

Let us know!

We’d be really happy if you sent us links to your projects where you use our component. Just send an email to [email protected] And do let us know if you have any questions or suggestion regarding the animation.

P.S. We’re going to publish more awesomeness wrapped in code and a tutorial on how to make UI for iOS (Android) better than better. Stay tuned!

License

The MIT License (MIT)

Copyright © 2018 Yalantis

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.
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].