Created
February 6, 2019 08:06
-
-
Save srfunksensei/7943d156f9b13772e4477d2bc56f99ad to your computer and use it in GitHub Desktop.
CarouselSample
This file contains hidden or 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
| // MARK: - DataSource | |
| extension CarouselPageViewController: UIPageViewControllerDataSource { | |
| func pageViewController(_: UIPageViewController, viewControllerBefore viewController: UIViewController) -> UIViewController? { | |
| guard let viewControllerIndex = items.index(of: viewController) else { | |
| return nil | |
| } | |
| let previousIndex = viewControllerIndex - 1 | |
| guard previousIndex >= 0 else { | |
| return items.last | |
| } | |
| guard items.count > previousIndex else { | |
| return nil | |
| } | |
| return items[previousIndex] | |
| } | |
| func pageViewController(_: UIPageViewController, viewControllerAfter viewController: UIViewController) -> UIViewController? { | |
| guard let viewControllerIndex = items.index(of: viewController) else { | |
| return nil | |
| } | |
| let nextIndex = viewControllerIndex + 1 | |
| guard items.count != nextIndex else { | |
| return items.first | |
| } | |
| guard items.count > nextIndex else { | |
| return nil | |
| } | |
| return items[nextIndex] | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment