An easy way to use pull-to-refresh

Overview

Version License Platform Support  Language

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 regularly updated some nice dynamic effect, at the same time also welcome to write to me ~

中文介绍 / 博客介绍

Screenshots

NormalAnimator SlackLoadingAnimator RamotionAnimator
FastAnimator

Requirements

  • Xcode 8 or later
  • iOS 8.0 or later
  • ARC
  • Swift 3.0 or later

Features

  • Support UIScrollView and its subclasses UICollectionView UITableView UITextView
  • Pull-Down to refresh and Pull-Up to load more
  • Support customize your own style(s)

Installation

CocoaPods

CocoaPods is the recommended way to add CRRefresh to your project.

Add a pod entry for CRRefresh to your Podfile.

pod 'CRRefresh'

Second, install CRRefresh into your project:

pod install

Carthage

Carthage is a decentralized dependency manager that builds your dependencies and provides you with binary frameworks. To integrate CRRefresh into your Xcode project using Carthage, specify it in your Cartfile:

github "CRAnimation/CRRefresh"

Run carthage update to build the framework and drag the built CRRefresh.framework (in Carthage/Build/iOS folder) into your Xcode project (Linked Frameworks and Libraries in Targets).

Manually

  1. Download the latest code version .
  2. Open your project in Xcode,drag the CRRefresh folder into your project. Make sure to select Copy items when asked if you extracted the code archive outside of your project.
  3. You need it with import CRRefresh .

Usage

Add CRRefresh to your project

import CRRefresh

Add pull-to-refresh

/// animator: your customize animator, default is NormalHeaderAnimator
tableView.cr.addHeadRefresh(animator: NormalHeaderAnimator()) { [weak self] in
    /// start refresh
    /// Do anything you want...
    DispatchQueue.main.asyncAfter(deadline: .now() + 2, execute: {
        /// Stop refresh when your job finished, it will reset refresh footer if completion is true
        self?.tableView.cr.endHeaderRefresh()
    })
}
/// manual refresh
tableView.cr.beginHeaderRefresh()

Add infinite-scrolling

/// animator: your customize animator, default is NormalFootAnimator
tableView.cr.addFootRefresh(animator: NormalFootAnimator()) { [weak self] in
    /// start refresh
    /// Do anything you want...
    DispatchQueue.main.asyncAfter(deadline: .now() + 2, execute: {
        /// If common end
        self?.tableView.cr.endLoadingMore()
        /// If no more data
        self?.tableView.cr.noticeNoMoreData()
		/// Reset no more data
		self?.tableView.cr.resetNoMore()
    })
}

Customize Style

Customize refresh need conform the CRRefreshProtocol protocol.

public protocol CRRefreshProtocol {
    /// Customize view
    var view: UIView {get}
    
    /// View insets
    var insets: UIEdgeInsets {set get}
    
    /// The height of the trigger to refresh
    var trigger: CGFloat {set get}
    
    /// The height of the animation is executed
    var execute: CGFloat {set get}
    
    /// Start refresh
    mutating func refreshBegin(view: CRRefreshComponent)
    
    /// End refresh
    mutating func refreshEnd(view: CRRefreshComponent, finish: Bool)
    
    /// Refresh the progress changes
    mutating func refresh(view: CRRefreshComponent, progressDidChange progress: CGFloat)
    
    /// Refresh the state changes
    mutating func refresh(view: CRRefreshComponent, stateDidChange state: CRRefreshState)
}

Remove

tableView.cr.removeFooter()
tableView.cr.removeHeader()

Contribution

You are welcome to contribute to the project by forking the repo, modifying the code and opening issues or pull requests.

Contacts

If you wish to contact me

License

CRRefresh is released under the MIT license. See LICENSE for details.

Comments
  • Ramotion Animation Intiializes with Circle Layer shown

    Ramotion Animation Intiializes with Circle Layer shown

    There is an issue with RamotionBallLayer()

    When you use the RamotionAnimation, a user can scroll down through a list (assuming the refresh is in header). When they scroll back up quickly, however, I noticed a bug where the while cirlce will appear, blocking content on the screen, even though it is not animating.

    A quick-fix for this would be set the 'isHidden' attribute in the initialization method as shown below:

    
    class RamotionBallLayer: CALayer {
    
    init(frame: CGRect, duration: CFTimeInterval, moveUpDist: CGFloat, color: UIColor = .white) {
            upDuration = duration
            super.init()
            self.frame = frame
            let circleWidth = min(frame.size.width, frame.size.height)
            circleLayer = CircleLayer(size: circleWidth, moveUpDist: moveUpDist, frame: frame, color: color)
            addSublayer(circleLayer)
    
            //  Hide the ball layer on init
            isHidden = true
        }
    
    }
    
    opened by jstngoulet 3
  • Missing files

    Missing files

    Hey,

    Thanks for your awesome repo.

    I installed it by using CocoaPods, I added this line to my Podfile: pod 'CRRefresh' However, there are many missing files as you can see in the attached image. what is the problem? I need to use FastAnimator but I can't because all its files didn't install.

    screen shot 2017-05-08 at 10 17 38 am
    opened by Maryom 2
  • 多次调用时,尤其弱网情况下,scrollview的contentInset.top计算有问题

    多次调用时,尤其弱网情况下,scrollview的contentInset.top计算有问题

    您好,首先很感谢作者写了这个纯swift的刷新控件库,通过学习源码,自己也学习了很多,再次感谢! 我在使用过程中遇到了上面的问题,猜测应该是在下拉刷新重新计算scrollview的contentInset.top时,多计算了一次animator.hold,导致刷新结束后,tableview会有向上偏移的情况,刚好偏移一个animator.hold。 项目进度原因,我并没有深入调用机制去查询根本原因,这里我用了比较trick的方法解决了此问题。 CRRefresh 版本 1.0.9 文件: CRRefreshHeaderView.swift lineNum: 104 screen shot 2018-08-10 at 1 28 13 pm

    如果作者有时间,麻烦看下此问题,期待下个版本解决,感谢!

    opened by lcl22hope 1
  • ScrollView partially hidden by navigation bar (large titles)

    ScrollView partially hidden by navigation bar (large titles)

    When we force refresh using the HeadRefresh (with NormalHeaderAnimator), when the scrollView populates with cells (in my case is a collectionView) the first cell is partially hidden behind the navigation bar, but after touching/scrolling the scrollView the collectionView automatically snaps itself on the correct position and the bug is gone.

    After headRefresh finishes to load the data: photo_2021-03-14 16 57 28

    After touching/scrolling the collectionView: photo_2021-03-14 16 57 31

    Has anyone experienced this before? How can I fix it?

    opened by Mattesackboy 5
  • No configurations or options available for UI components

    No configurations or options available for UI components

    Hi, I'm just wondering if this library can have the options to change the title color or pull to refresh description, or the color of the activity indicator etc.

    Thanks

    opened by hassan31 0
  • Pull to Refresh breaks with iOS13

    Pull to Refresh breaks with iOS13

    It doesn't appear that there is much activity support iOS13/Swift 5, so thought I'd drop a very hacky solution for supporting pull-to-refresh, particularly in a modal.

    Since CRRefresh uses tableView.addSubview instead of tableView.refreshControl, the experience gets a bit odd in iOS13, in particular with modal sheets. Pulling down to refresh will actually dismiss the modal, instead of refreshing the tableView. There are some solutions that use isModalInPresentation = true, but that allows for a slight drag of the modal, and no affordance showing that PTR is happening. See this SO thread:

    My solution was to fake the RefreshControl, but hide it.

    extension UITableView {
      func iOS13RefreshControlHack() {
        if #available(iOS 13.0, *) {
          let refreshControl       = UIRefreshControl()
          refreshControl.tintColor = .clear
          
          self.refreshControl      = refreshControl
          self.refreshControl?.addTarget(self, action: #selector(handleRefreshControl), for: .valueChanged)
        }
      }
      
      @objc func handleRefreshControl() {
        self.refreshControl?.endRefreshing()
      }
    }
    

    Then call from your tableView via (or whatever better name you choose):

    self.tableView.iOS13RefreshControlHack()
    

    This triggers the modal to behave properly when PTR is requested, but also continues to show the CRRefresh custom spinners/checkmark instead. In addition, you can still dismiss the modal by pulling down from the navigationBar, but the modal does not move when pulling on the table cells.

    Hope it helps someone.

    opened by rscherf 0
Owner
CRAnimation
CRAnimation
Easily add vertical and horizontal pull to refresh to any UIScrollView. Can also add multiple pull-to-refesh views at once.

This is a fork from the famous SVPullToRefresh pod with 2 additional functionalities: Can add multiple pull-to-refresh views into one single UIScrollV

Hoang Tran 42 Dec 28, 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
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
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
Elastic pull to refresh for iOS developed in Swift

DGElasticPullToRefresh Elastic pull to refresh compontent developed in Swift Inspired by this Dribbble post: Pull Down to Refresh by Hoang Nguyen Tuto

Danil Gontovnik 3.7k Jan 3, 2023
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
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
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
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
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
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
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
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
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
PullToRefreshSwiftUI - Pull to refresh for SwiftUI

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

Dmitry Kononchuk 1 Feb 28, 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
Easy background refresh registration, scheduling, execution, and completion. BGTaskScheduler for the lazy.

EasyBackgroundRefresh Easy background refresh registration, scheduling, execution, and completion. BGTaskScheduler for the lazy. Usage For fast refres

Yonat Sharon 6 Dec 5, 2022