Skip to content

7glyphs/JRPageViewControllerKit

 
 

Repository files navigation

JRPageViewControllerKit

Build Status Version Status Carthage compatible Platform license MIT

JRPageViewControllerKit wraps all the boilerplate code that is required for the implementation of UIPageViewController.

About

This library aims to wrap all the boilerplate code that is required for the implementation of the UIPageViewController. Within a few lines of code you have a UIPageViewController ready to run. In order to achieve that this library overrides the UIPageViewControllerDataSource and UIPageViewControllerDelegate with a custom implementation. It also implements the UIScrollViewDelegate of the scrollview that is within the UIPageViewController.

Requirements

  • iOS 8+
  • Swift 4.0
  • Xcode 9

Installation

use_frameworks!

pod 'JRPageViewControllerKit'
github "psartzetakis/JRPageViewControllerKit"

Getting Started

import JRPageViewControllerKit

Example

// 1. Create a factory that will return viewController for a specific index.
let factory: ((Int) -> ChildViewController?) = { [unowned self] index -> ChildViewController? in
    let viewController = self.storyboard!.instantiateViewController(withIdentifier: "ChildViewController") as! ChildViewController
    viewController.index = index
    return viewController
}

// 2. Instantiate a PageViewControllerManager.
let pageViewControllerManager = PageViewControllerManager(insertIn: containerView, inViewController: self, totalPages: 6, viewControllerForIndex: factory)

// 3. Get notified when user swiped to another viewController.
pageViewControllerManager.didScrollToIndex = { index in
    // The index that the user has just scrolled.
}

// 4. Get notified when another viewController is about to be appeared.
pageViewControllerManager.nextViewControllerAppears = { [unowned self] direction, ratio, destinationIndex in
    let ratio = String(format: "%.2f", ratio)
    let text = "direction:\(direction.rawValue), ratio:\(ratio),\n  to \(destinationIndex)"
}

Licence

JRPageViewControllerKit is being provided under MIT Licence.

Copyright © 2016-present Panagiotis Sartzetakis

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Swift 96.6%
  • Ruby 2.3%
  • Objective-C 1.1%