Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Custom page view controller #468

Merged
merged 12 commits into from
Apr 22, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
import UIKit
import Parchment

/// Parchment provides a custom `UIPageViewController` alternative
/// if you need better delegate methods called `PageViewController`.
class PageViewExampleViewController: UIViewController {
let viewControllers: [UIViewController] = [
ContentViewController(index: 0),
ContentViewController(index: 1),
ContentViewController(index: 2),
ContentViewController(index: 3),
ContentViewController(index: 4),
]

override func viewDidLoad() {
let pageViewController = PageViewController()
pageViewController.dataSource = self
pageViewController.delegate = self
pageViewController.selectViewController(viewControllers[0], direction: .none)

addChild(pageViewController)
view.addSubview(pageViewController.view)
view.constrainToEdges(pageViewController.view)
pageViewController.didMove(toParent: self)
}
}

extension PageViewExampleViewController: PageViewControllerDataSource {
func pageViewController(
_ pageViewController: PageViewController,
viewControllerBeforeViewController viewController: UIViewController) -> UIViewController? {
guard let index = viewControllers.firstIndex(of: viewController) else { return nil }
if index > 0 {
return viewControllers[index - 1]
}
return nil
}

func pageViewController(
_ pageViewController: PageViewController,
viewControllerAfterViewController viewController: UIViewController) -> UIViewController? {
guard let index = viewControllers.firstIndex(of: viewController) else { return nil }
if index < viewControllers.count - 1 {
return viewControllers[index + 1]
}
return nil
}
}

extension PageViewExampleViewController: PageViewControllerDelegate {
func pageViewController(_ pageViewController: PageViewController, willStartScrollingFrom startingViewController: UIViewController, destinationViewController: UIViewController) {
print("willStartScrollingFrom: ",
startingViewController.title ?? "",
destinationViewController.title ?? "")
}

func pageViewController(_ pageViewController: PageViewController, isScrollingFrom startingViewController: UIViewController, destinationViewController: UIViewController?, progress: CGFloat) {
print("isScrollingFrom: ",
startingViewController.title ?? "",
destinationViewController?.title ?? "",
progress)
}

func pageViewController(_ pageViewController: PageViewController, didFinishScrollingFrom startingViewController: UIViewController, destinationViewController: UIViewController, transitionSuccessful: Bool) {
print("didFinishScrollingFrom: ",
startingViewController.title ?? "",
destinationViewController.title ?? "",
transitionSuccessful)
}
}
5 changes: 5 additions & 0 deletions Example/ExamplesViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ enum Example: CaseIterable {
case scroll
case header
case multipleCells
case pageViewController

var title: String {
switch self {
Expand Down Expand Up @@ -40,6 +41,8 @@ enum Example: CaseIterable {
return "Header above menu"
case .multipleCells:
return "Multiple cells"
case .pageViewController:
return "PageViewController"
}
}
}
Expand Down Expand Up @@ -118,6 +121,8 @@ final class ExamplesViewController: UITableViewController {
return HeaderViewController(nibName: nil, bundle: nil)
case .multipleCells:
return MultipleCellsViewController(nibName: nil, bundle: nil)
case .pageViewController:
return PageViewExampleViewController(nibName: nil, bundle: nil)
}
}

Expand Down
68 changes: 62 additions & 6 deletions Parchment.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

673 changes: 0 additions & 673 deletions Parchment/Classes/EMPageViewController.swift

This file was deleted.

Loading