Coder Social home page Coder Social logo

mdcscrollbarlabel's Introduction

MDCScrollBarLabel

An animated scroll bar to present extra information when scrolling on a UIScrollView.

Y'know, like the clock on Path.

MDCScrollBarLabel GIF

Usage

Basically, you have two options. You can:

  • Subclass MDCScrollBarViewController and set an MDCScrollBarLabel to its scrollBarLabel property.
  • Implement a UIViewController which is a UIScrollBarDelegate, then call the fade in/out logic for the label as you'd like.

See the example application for usage.

Subclassing MDCScrollBarViewController

#pragma mark - Creating the Scroll Bar Label

- (void)viewDidLoad {
    [super viewDidLoad];

    // Create a table view with a row height of 100.f
    CGSize size = self.view.frame.size;
    self.tableView = [[UITableView alloc] initWithFrame:self.view.bounds
                                                  style:UITableViewStylePlain];
    self.tableView.delegate = self;
    self.tableView.dataSource = self;
    self.tableView.rowHeight = 100.f;
    [self.view addSubview:self.tableView];

    // Add a scroll bar label to the table view
    self.scrollBarLabel = [[MDCScrollBarLabel alloc] initWithScrollView:self.tableView];
    [self.tableView addSubview:self.scrollBarLabel];
}

#pragma mark - Updating the Date on the Scroll Bar Label

- (void)scrollViewDidScroll:(UIScrollView *)scrollView {
    [super scrollViewDidScroll:scrollView];

    // Determine which row the scroll bar label is currently hovering over
    NSInteger rowNumber = CGRectGetMinY(self.scrollBarLabel.frame) / 100.f;

    // Update the date on the label using the model data for that row
    // (here we assume you have a model named `Event`)
    Event *event = self.events[rowNumber];
    self.scrollBarLabel.date = event.date;
}

Subclassing UIViewController <UIScrollViewDelegate>

#pragma mark - Show/Hide the Label Using UIScrollViewDelegate Callbacks

- (void)scrollViewDidScroll:(UIScrollView *)scrollView {
    [self.scrollBarLabel adjustPositionForScrollView:scrollView];
    [self.scrollBarLabel setDisplayed:YES animated:YES afterDelay:0.0f];
}

- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView {
    [self.scrollBarLabel setDisplayed:NO animated:YES afterDelay:self.scrollBarFadeDelay];
}

- (void)scrollViewDidEndDragging:(UIScrollView *)scrollView
                  willDecelerate:(BOOL)decelerate {
    if (!decelerate) {
        [self.scrollBarLabel setDisplayed:NO animated:YES afterDelay:self.scrollBarFadeDelay];
    }
}

- (void)scrollViewDidEndScrollingAnimation:(UIScrollView *)scrollView {
    [self.scrollBarLabel setDisplayed:NO animated:YES afterDelay:self.scrollBarFadeDelay];
}

- (void)scrollViewDidScrollToTop:(UIScrollView *)scrollView {
    [self.scrollBarLabel setDisplayed:NO animated:YES afterDelay:self.scrollBarFadeDelay];
}

License

MIT license. See the LICENSE file for details.

mdcscrollbarlabel's People

Contributors

modocache 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.