Giter Site home page Giter Site logo

drpaginatedscrollview's Introduction

DRPaginatedScrollView

Implement a paginated scroll view really easily using blocks.

DRPaginatedScrollView GIF

DRPaginatedScrollView GIF

Features

  • Block-driven pages setup.
  • Jump between pages (with bouncy effect).
  • Automatic jump to the next page by tapping.
  • Autolayout-compatible.
  • Portrait and landscape orientations support.

CocoaPods

You can install DRPaginatedScrollView through CocoaPods adding the following to your Podfile:

pod 'DRPaginatedScrollView'

How to use

Getting page-related information

- (NSInteger)currentPage
  • Returns: index of the current page displaying (indexes start from 0).
- (NSInteger)nextPage
  • Returns: index of the next page (indexes start from 0).
- (NSInteger)lastPage
  • Returns: index of the last page (indexes start from 0).
- (NSInteger)numberOfPages
  • Returns: the current number of pages of the paginated scroll view.

Setting up pages

- (void)addPageWithHandler:(void (^)(UIView * pageView))handler
  • handler is a block passing the view that will contain the subviews for the new page, so in that block you just need to add all the views to be displayed on that page to the pageView. It'll just work.

Applying autolayout on the subviews is not obligatory, but recommended.

Anyway, if you decide to use autolayout I suggest using a framework called Masonry. Pretty great stuff.

Here's an example without using autolayout, to simplify things. If you want to see an example of this implementation using autolayout, check out the demo app:

[paginatedScrollView addPageWithHandler:^(UIView * pageView) {
    UIView * square = [UIView new];
    [square setBackgroundColor:[UIColor redColor]];
    [square setFrame:CGRectMake(0, 0, 100, 100)];
    
    [pageView addSubview:square];
}];

Jumping between pages

- (void)jumpToPage:(NSInteger)page bounce:(CGFloat)bounce completion:(void (^)(void))completion
  • page specifies the index of the page to jump.
  • bounce specifies the amount of bouncy effect the jump will be performed with. Recommended values are 0-40, being 0 the total absence of bounce.
  • completion is a block that will be executed after the jump is performed.

Here are some examples:

// Jumping to the 4th page with no bounce effect and completion

[paginatedScrollView jumpToPage:3 bounce:0 completion:^{
	NSLog(@"Jump finished!");
}];

// Jumping to the first page with a normal bounce effect and no completion

[paginatedScrollView jumpToPage:0 bounce:20 completion:nil];

// Jumping to the next page with a little bounce effect and no completion

[paginatedScrollView jumpToPage:[paginatedScrollView nextPage] bounce:10 completion:nil];

// Jumping to the last page with a high bounce effect and no completion

[paginatedScrollView jumpToPage:[paginatedScrollView lastPage] bounce:40 completion:nil];

Controlling details of jumps between pages

BOOL isJumping
  • Description: whether the paginated scroll view is currently jumping between pages or not.
NSTimeInterval jumpDurationPerPage
  • Description: the duration each page will last jumping with when jumping through multiple pages.
  • Default value: 0.1
  • Recommended value: 0.05-0.175

Handling taps on the view

void (^actionWhenTappedBlock)(DRPaginatedScrollView *)
  • Description: action that executes when the paginated scroll view is tapped.

  • Default value:

     ^(DRPaginatedScrollView * paginatedScrollView) {
     	[paginatedScrollView jumpToPage:[paginatedScrollView nextPage] bounce:0 completion:nil];
     }
  • Recommended value: any.

Wish list

  • CocoaPods support.
  • Being able to add gaps between pages.
  • Automatic block-customizable page indicator (paginatedScrollView configurePageIndicatorWithHandler:).
  • Being able to clip any subview until a determined page (pageView clipSubview:untilPage:) and forever (pageView clipSubviewForever:).

Requirements

  • iOS 6 or higher.
  • Automatic Reference Counting (ARC).

License

DRPaginatedScrollView is available under the MIT license.

Also, I'd really love to know you're using it in any of your projects, so send me an email or a tweet and make my day :)

drpaginatedscrollview's People

Watchers

Mauricio Vargas avatar James Cloos 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.