A pull-down-to-refresh control for iOS that plays pong, originally created for the MHacks III iOS app

Overview

BOZPongRefreshControl

A pull-down-to-refresh control for iOS that plays pong

Installation

It's on CocoaPods! Put pod 'BOZPongRefreshControl' in your Podfile.

Alternatively, just place BOZPongRefreshControl.h and BOZPongRefreshControl.m in your project anywhere you'd like.

Usage

Attach it to a UITableView or UIScrollView like so:

- (void)viewDidLoad
{
    [super viewDidLoad];
    
    /* NOTE: Do NOT attach the refresh control in viewDidLoad!
     * If you do this here, it'll act very funny if you have
     * a navigation bar or other such similar thing that iOS
     * automatically offsets content for. You have to wait for
     * the subviews to get laid out first so the refresh
     * control knows how big that offset is!
     */
}

- (void)viewDidLayoutSubviews
{
    self.pongRefreshControl = [BOZPongRefreshControl attachToTableView:self.tableView
                                                     withRefreshTarget:self
                                                      andRefreshAction:@selector(refreshTriggered)];
}

Then, implement UIScrollViewDelegate in your UIViewController if you haven't already, and pass the calls through to the refresh control:

- (void)scrollViewDidScroll:(UIScrollView *)scrollView
{
    [self.pongRefreshControl scrollViewDidScroll];
}

- (void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate
{
    [self.pongRefreshControl scrollViewDidEndDragging];
}

Lastly, make sure you've implemented the refreshAction you passed it earlier to listen for refresh triggers:

- (void)refreshTriggered
{
    //Go and load some data

    //Finshed loading the data, reset the refresh control
    [self.pongRefreshControl finishedLoading];
}

For more details, check out the demo app's code. It has examples for using the refresh control on a UIScrollView and outside of a UITableViewController.

Configuration

  • Set the foreground color with the foregroundColor property
  • Set the background color with the backgroundColor property
  • Adjust how fast it plays by changing the totalHorizontalTravelTimeForBall property

Known Issues/To Do

  • It'll interfere with UIScrollView content that's above y = 0.0f
  • I haven't tested it, but I'd be willing to bet it looks a bit silly on iPads
  • Test it out on a physical iPhone 6+
  • The behavior of the paddles needs a little work
  • The the UIScrollView that it's attached to is scrolled automatically, the refresh control may be scrolled down into view under some circumstances (expanding/collapsing UITableViewCells, for example)
  • Tests!
Comments
  • Don't overwrite table header, beginLoadingAnimated:, bugfixes

    Don't overwrite table header, beginLoadingAnimated:, bugfixes

    -I use table view headers in my app, so this was my main motivation for this pull request. These no longer get overwritten.

    -UITableView is a UIScrollView, so no reason (as far as I can tell?) to have separate functions for each. attachToTableView now calls attachToScrollView.

    -beginLoadingAnimated allows you to choose if you want to animate the appearance of the refresh control, or have it show up instantly. Also, in my previous pull request, I didn't set the state to Refreshing in beginLoading, which was causing problems, so i fixed that too.

    -Some of the math with the content insets was weird, so I simplified it a bit. Now, the content inset is only changed when beginLoading is called (to add REFRESH_CONTROL_HEIGHT), and when finishedLoading is called (to switch back to the original).

    -Reduced overall length by about 60 lines, and I've tested the demo project and everything seems to still work. I'm uncertain if the the coverView functionality still works; I don't really understand what the purpose of it is, so I can't tell if I've broken it. Let me know if I need to fix it.

    opened by jconst 6
  • strong scrollView and refreshTarget properties create a retain cycle

    strong scrollView and refreshTarget properties create a retain cycle

    In BOZPongRefreshControl.m line 58. The properties scrollView and refreshTarget should be weak, not strong. This class does not own these objects, so it should not retain them. This memory leak can be shown in the example project by running the Instruments allocation tool. Every time you open/close the "On a ScrollView" option, it adds ~350KB of memory usage because it is keeping every instance of the scrollView in memory that you ever open. This may not be much in this case, but it my project it was keeping open ~6MB of memory each time.

    opened by CZyMfnIPC 4
  • "Play" pong while loading.

    I have added interactivity to the control. When you set the property interactive to YES, the scrolling of the scrollView/tableView controls the vertical position of the right paddle.

    Fun fact: I have added an artificial delay for one of the reload operations in my App to let the user play for a few seconds. :)

    opened by dasdom 4
  • Added rotation/landscape support

    Added rotation/landscape support

    When the user rotates the device, the view will adjust its frame, set the paddles/ball at the appropriate positions, and resume animation.

    Note: There is still an issue with the cover view in landscape orientation and when the user rotates the device from a different view controller and returns to the previous one.

    Also, I'm relatively new to GitHub and any feedback on the effectiveness of my code would be highly appreciated.

    opened by MahirEusufzai 3
  • Controlling left paddle via motion

    Controlling left paddle via motion

    I was considering modifying the project so that the user can control one of the paddles by tilting the iPhone/Pad . (Keeping the current system would also be an option.) Is this something worth doing?

    opened by MahirEusufzai 2
  • BOZPongRefreshControl stops when another view is pushed

    BOZPongRefreshControl stops when another view is pushed

    The refreshControl is playing its animation, then I push a second viewcontroller. I press the back button and the refreshcontrol is stucked. How do we keep the animation playing?

    opened by Jayvd 0
  • Default state for the reflectedBallDirection point.

    Default state for the reflectedBallDirection point.

    Added a default state for the reflectedBallDirection point in -determineReflectedDirectionOfBall to ensure a garbage value won't be returned in the -determineNextBallDestination method.

    opened by ajfigueroa 0
  • Autorotation breaks the refresh control (when app itself does not support autorotate)

    Autorotation breaks the refresh control (when app itself does not support autorotate)

    My app has autorotation turned off (Portrait only).

    When I pull down on the refresh control to expose the Pong view, then rotate, the Pong view will disappear and the table offset will still be there.

    When I try to pull down again, nothing happens, when I let go, the Pong view shows up again and closes, causing the table offset to go back to normal.

    My solution, remove the NotificationCenter observer for changeOrientation because I will never need it. Perhaps in the future a property can be created in BOZPongRefreshControl to enable/disable the autorotation code after initializing it.

    opened by CZyMfnIPC 2
  • Is this maintained / does it work with the latest iOS and swift?

    Is this maintained / does it work with the latest iOS and swift?

    This is the greatest idea since sliced bread! Would love to use this in my project. However does not seem like it is still maintained. Will this work well with the latest iOS version and play well with swift?

    opened by itsjms 1
  • BOZPongRefreshControl stops when user press home button and gettig back in

    BOZPongRefreshControl stops when user press home button and gettig back in

    hello, cool control you have here. But one problem is that, the control stops when user press home button and open the app back.

    viewWillAppear and viewWillDisappear cannot solve the problem

    opened by Jayvd 0
  • Issue when the system scrolls the table view automatically

    Issue when the system scrolls the table view automatically

    If the table view is scrolled without user interaction, the pong view will not know the current offset of the table, so it may show up on screen unintentionally.

    The case that I ran into: I have cells that expand/collapse when they are tapped. If you tap a cell in the middle of the table, the device will automatically move the cells below, thus having no effect on the position of the Pong view up above. However if you tap the last item in the list, it will move everything above. When collapsing, it will scroll the cells down, which also brings down the pong view.

    As soon as I scroll the table manually, it sees the correct offset and removes the pong view.

    My fix for this was to include a call to "[self.pongRefreshControl scrollViewDidScroll];" after the cell is collapsed, which allows the pong view to update to the correct offset with the new table position.

    Maybe this isn't a full-on bug, because I can't find a solution without a major refactor in the Pong library, but it should probably be included in the ReadMe as a footnote to call scrollViewDidScroll in cases where the table might be scrolled outside of "scrollViewDidScroll"

    opened by CZyMfnIPC 1
  • Start the animation when the user pulls down

    Start the animation when the user pulls down

    First of all - this is fantastic, very well done - really cool and awesome!!! :) Congrats!

    Would be awesome to have the user be able to see the animation for fun when they pull down - right now the requests are pretty fast so the user only sees the animation for a short time (since the animation starts when the control is pulled down and released).

    See the other apps that do it this way - Snapchat, new YikYak.

    Sweet job, this is really cool!

    (Also I tried decreasing the ball travel time to 0.5 to show the user more of the game / make it clearer what is happening when they pull down and it seemed rushed. I think the solution is just to make the game show for longer, it's fun to watch and I'm sure people will refresh just to see it!)

    opened by nikilster 1
Releases(1.0.1)
  • 1.0.1(Oct 16, 2014)

    Changes:

    • Fixed a memory leak caused by a strong retain cycle
    • Fixed a bug introduced in iOS 8 that causes stutter when the user triggers a refresh

    Thanks to @IPCStudios for catching the memory leak and suggesting the fix!

    Source code(tar.gz)
    Source code(zip)
  • 1.0.0(Jan 24, 2014)

    Changes:

    • Orientation changes work!
    • Refresh control attachment now works the same for UIScrollViews and UITableViews
    • Added a beginLoading function to manually start a refresh
    • Took out the cover view and corresponding property, it now hides the refresh control by shrinking it
    • Made the default game speed a little faster
    • Other minor improvements/cleaning

    Thanks to @jconst, @MahirEusufzai, and @ajfigueroa for their contributions!

    Source code(tar.gz)
    Source code(zip)
Owner
Ben Oztalay
Ben Oztalay
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
✳️ 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
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, 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
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
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
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