-
Notifications
You must be signed in to change notification settings - Fork 424
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #537 from rechsteiner/3.0
Version 3.0
- Loading branch information
Showing
34 changed files
with
3,997 additions
and
912 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
70 changes: 70 additions & 0 deletions
70
Example/Examples/PageViewController/PageViewExampleViewController.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.