PaginatedScrollView 0.2.0

PaginatedScrollView 0.2.0

测试已测试
语言语言 SwiftSwift
许可协议 MIT
发布时间最后发布2017年2月
SwiftSwift版本3.0
SPM支持SPM

Elvis Nuñez维护。



  • 作者:
  • Elvis Nuñez

PaginatedScrollView

简单分页UIScrollView子类,支持用作页面的UIViewControllers。它还处理旋转效果相当不错。

用法

import UIKit

class RootController: UIViewController {
    var pages: [UIViewController] {
        let firstController = UIViewController()
        firstController.view.backgroundColor = UIColor.redColor()

        let secondController = UIViewController()
        secondController.view.backgroundColor = UIColor.greenColor()

        let thirdController = UIViewController()
        thirdController.view.backgroundColor = UIColor.purpleColor()

        return [firstController, secondController, thirdController]
    }

    lazy var scrollView: PaginatedScrollView = {
        let view = PaginatedScrollView(frame: view.frame, parentController: self, initialPage: 0)
        view.viewDataSource = self

        return view
    }()

    override func viewDidLoad() {
        super.viewDidLoad()

        view.addSubview(scrollView)
    }

    override func viewWillLayoutSubviews() {
        super.viewWillLayoutSubviews()

        scrollView.configure()
    }
}

extension RootController: PaginatedScrollViewDataSource {
    func numberOfPagesInPaginatedScrollView(paginatedScrollView: PaginatedScrollView) -> Int {
        return pages.count
    }

    func paginatedScrollView(paginatedScrollView: PaginatedScrollView, controllerAtIndex index: Int) -> UIViewController {
        return pages[index]
    }
}

PaginatedScrollViewDelegate

当涉及到精确知道何时切换到下一页或返回到上一页时,`UIPageViewController`相当薄弱。这就是为什么存在`PaginatedScrollView`的主要原因。

protocol PaginatedScrollViewDelegate: class {
    func paginatedScrollView(paginatedScrollView: PaginatedScrollView, didMoveToIndex index: Int)
    func paginatedScrollView(paginatedScrollView: PaginatedScrollView, didMoveFromIndex index: Int)
}

安装

PaginatedScrollView可通过CocoaPods获取。要安装它,只需在Podfile中添加以下行:

pod 'PaginatedScrollView'

PaginatedScrollView还通过Carthage提供。要安装它,只需在Cartfile中添加以下行:

github "3lvis/PaginatedScrollView"

许可协议

PaginatedScrollView采用MIT许可协议。有关更多信息,请参阅LICENSE文件。

作者

Elvis Nuñez,@3lvis