JRPageViewControllerKit 1.1.0

JRPageViewControllerKit 1.1.0

测试已测试
语言语言 SwiftSwift
许可证 MIT
发布最后发布2017年10月
SwiftSwift 版本4.0
SPM支持 SPM

Panagiotis Sartzetakis 维护。







JRPageViewControllerKit 封装了实现 UIPageViewController 所必需的所有样板代码。

关于

这个库旨在封装实现 UIPageViewController 所必需的所有样板代码。只需几行代码,你就可以拥有一个可以运行的 UIPageViewController。为了实现这一目标,该库使用自定义实现重写了 UIPageViewControllerDataSourceUIPageViewControllerDelegate,同时也实现了 UIPageViewController 内部的滚动视图的 UIScrollViewDelegate

要求

  • iOS 8+
  • Swift 4.0
  • Xcode 9

入门

import JRPageViewControllerKit

示例

// 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)"
}

许可证

JRPageViewControllerKit 根据 MIT 许可证 提供。

版权 © 2016 年至今 Panagiotis Sartzetakis