Giter VIP home page Giter VIP logo

scpageviewcontroller's Introduction

SCPageViewController

SCPageViewController is a container view controller similar to UIPageViewController but which provides more control, is much more customizable and, arguably, has a better overall design. It supports the following features:

  • Customizable transitions and animations (through layouters and custom easing functions)
  • Incremental updates with user defined animations
  • Bouncing and realistic physics
  • Correct appearance calls, even while interactions are in progres
  • Custom layouts and animated layout changes
  • Vertical and horizontal layouts
  • Pagination
  • Content insets
  • Completion blocks
  • Customizable interaction area and number of touches required

and more..

Screenshots

Implementation details

SCPageViewController is build on top of an UIScrollView subclass (SCScrollView) which provides it with correct physics, callbacks for building the pagination, navigational constraints and custom transitions. It also can work with user defined interaction areas and minimum/maximum number of touches. It's worth noting that SCScrollView also powers SCStackViewController

SCPageViewController relies on page layouters to know where to place each of the controllers at every point. Page layouters are built on top of a simple protocol with methods for providing the final and intermediate view controller frames, and custom animations for page insertions, deletions, moves and reloads. The demo project contains 4 examples: plain with inter-item spacings, parallax, sliding and cards.

Usage

  • Create a new instance and set its data source and delegate
    self.pageViewController = [[SCPageViewController alloc] init];
    [self.pageViewController setDataSource:self];
    [self.pageViewController setDelegate:self];
  • SCPageViewController relies on layouters that define how pages are layed out. You can use one of the included ones or create a custom class that implements the SCPageLayouterProtocol.
    [self.pageViewController setLayouter:[[SCPageLayouter alloc] init] animated:NO completion:nil];
  • Implement the SCPageViewControllerDataSource which defines the total number of pages and the view controllers to be used for each of them.
- (NSUInteger)numberOfPagesInPageViewController:(SCPageViewController *)pageViewController;

- (UIViewController *)pageViewController:(SCPageViewController *)pageViewController viewControllerForPageAtIndex:(NSUInteger)pageIndex;
  • Optionally, modify the following properties to your liking
    // Enable/disable pagination
    [self.pageViewController setPagingEnabled:NO];
    
    // Ignore navigation contraints (bounce between pages)
    [self.pageViewController setContinuousNavigationEnabled:YES];

    // Have the page view controller come to a rest slower
    [self.pageViewController setDecelerationRate:UIScrollViewDecelerationRateNormal];

    // Disable bouncing
    [self.pageViewController setBounces:NO];

    // Customize how many number of touches are required to interact with the pages
    [self.pageViewController.scrollView.panGestureRecognizer setMinimumNumberOfTouches:2];
    [self.pageViewController.scrollView setMaximumNumberOfTouches:1];
    
    // Allow interaction only in the specified area
    //SCScrollViewTouchApprovalArea *touchApprovalArea = [[SCScrollViewTouchApprovalArea alloc] init];
    //[touchApprovalArea setPath:[UIBezierPath bezierPathWithRect:someFrame]];
    //[self.pageViewController.scrollView addTouchApprovalArea:touchApprovalArea];
    
    //Use different easing functions for animations and navigation
    [self.pageViewController setEasingFunction:[SCEasingFunction easingFunctionWithType:SCEasingFunctionTypeLinear]];
    
    // Change the default animation durations
    [self.pageViewController setAnimationDuration:1.0f];

#####Incremental updates SCPageViewController also supports incremental updates and all the animations are customizable through the layouter.

	[self.pageViewController insertPagesAtIndexes:(NSIndexSet *)indexes animated:(BOOL)animated completion:^(void)completion];

	[self.pageViewController deletePagesAtIndexes:(NSIndexSet *)indexes animated:(BOOL)animated completion:^(void)completion]

	[self.pageViewController reloadPagesAtIndexes:(NSIndexSet *)indexes animated:(BOOL)animated completion:^(void)completion]

	[self.pageViewController movePageAtIndex:(NSUInteger)fromIndex toIndex:(NSUInteger)toIndex animated:(BOOL)animated completion:^(void)completion]

#####Easing functions

SCPageViewController can work with custom easing functions defined through the SCEasingFunctionProtocol. It comes bundled with 31 different ones (thanks to AHEasing) and new ones can be created with ease.

  • Ease In Out Back Plain+BackEaseInOut

  • Ease Out Bounce Plain+BounceEaseOut

  • Ease Out Elastic Plain+ElasticEaseOut

For more usage examples please have a look at the included demo project (or pod try SCPageViewController)

License

SCPageViewController is released under the MIT License (MIT) (see the LICENSE file)

Contact

Any suggestions or improvements are more than welcome and I would also love to know if you are using this component in a published application. Feel free to contact me at [email protected] or @stefanceriu.

scpageviewcontroller's People

Contributors

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