The minimum setup to get started using the UIPageViewController.
(Xcode 8, Swift 3.0)
class ViewController: UIPageViewController, UIPageViewControllerDataSource { var pages: [UIViewController] = [UIViewController]() override func viewDidLoad() { super.viewDidLoad() dataSource = self pages.append(UIStoryboard(name: "Main", bundle: nil) .instantiateViewController(withIdentifier: "Page1")) pages.append(UIStoryboard(name: "Main", bundle: nil) .instantiateViewController(withIdentifier: "Page2")) pages.append(UIStoryboard(name: "Main", bundle: nil) .instantiateViewController(withIdentifier: "Page3")) setViewControllers([pages.first!], direction: .forward, animated: true, completion: nil) } func pageViewController(_ pageViewController: UIPageViewController, viewControllerBefore viewController: UIViewController) -> UIViewController? { let index = pages.index(of: viewController)! if index == 0 { return nil } return pages[index - 1] } func pageViewController(_ pageViewController: UIPageViewController, viewControllerAfter viewController: UIViewController) -> UIViewController? { let index = pages.index(of: viewController)! if index == pages.count - 1 { return nil } return pages[index + 1] } func presentationCount(for pageViewController: UIPageViewController) -> Int { return pages.count } func presentationIndex(for pageViewController: UIPageViewController) -> Int { return 0 } }
(Xcode 8, Swift 3.0)
No comments:
Post a Comment
Note: Only a member of this blog may post a comment.