Coder Social home page Coder Social logo

echohuub / bozpongrefreshcontrol Goto Github PK

View Code? Open in Web Editor NEW

This project forked from boztalay/bozpongrefreshcontrol

0.0 2.0 0.0 501 KB

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

License: MIT License

bozpongrefreshcontrol's Introduction

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 7
     * 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
  • The behavior of the paddles needs a little work
  • Tests!

bozpongrefreshcontrol's People

Contributors

ajfigueroa avatar boztalay avatar jconst avatar mahireusufzai avatar

Watchers

 avatar  avatar

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.