Don't allow swiping in SegmentedPageViewController

This commit is contained in:
Shadowfacts 2019-09-14 15:59:17 -04:00
parent 88344c67e8
commit d3e31541cf
1 changed files with 2 additions and 16 deletions

View File

@ -8,7 +8,7 @@
import UIKit
class SegmentedPageViewController: UIPageViewController, UIPageViewControllerDataSource, UIPageViewControllerDelegate {
class SegmentedPageViewController: UIPageViewController, UIPageViewControllerDelegate {
let titles: [String]
let pageControllers: [UIViewController]
@ -23,7 +23,6 @@ class SegmentedPageViewController: UIPageViewController, UIPageViewControllerDat
super.init(transitionStyle: .scroll, navigationOrientation: .horizontal, options: nil)
self.dataSource = self
self.delegate = self
}
@ -54,20 +53,7 @@ class SegmentedPageViewController: UIPageViewController, UIPageViewControllerDat
@objc func segmentedControlChanged() {
selectPage(at: segmentedControl.selectedSegmentIndex, animated: true)
}
// MARK: - Page View Controller Data Source
func pageViewController(_ pageViewController: UIPageViewController, viewControllerBefore viewController: UIViewController) -> UIViewController? {
guard let index = pageControllers.firstIndex(of: viewController),
index > 0 else { return nil }
return pageControllers[index - 1]
}
func pageViewController(_ pageViewController: UIPageViewController, viewControllerAfter viewController: UIViewController) -> UIViewController? {
guard let index = pageControllers.firstIndex(of: viewController),
index < pageControllers.count - 1 else { return nil }
return pageControllers[index + 1]
}
// MARK: - Page View Controller Delegate
func pageViewController(_ pageViewController: UIPageViewController, didFinishAnimating finished: Bool, previousViewControllers: [UIViewController], transitionCompleted completed: Bool) {
currentIndex = pageControllers.firstIndex(of: viewControllers!.first!)!