To make UIPageViewController available, you must implement the UIPageViewControllerDataSource protocol and provide a view controller for the pageViewController(pageViewController:viewControllerBeforeViewController) -> UIViewController? methods pageViewController(pageViewController:viewControllerBeforeViewController) -> UIViewController? and ...viewControllerAfterViewController) .
Provide a custom view controller for each page that displays the image and label, and accept them as properties so you can provide them from PageViewController.
My trick is to create a method that creates a new view controller in these methods:
// MARK:- UIPageViewControllerDataSource extension MyPageViewController: UIPageViewControllerDataSource { func viewControllerWithIndex(var index: Int) -> UIViewController! { let viewController = storyboard?.instantiateViewControllerWithIdentifier("MyViewController") as! MyViewController // This VC has to be in the storyboard, otherwise just use MyVC() // Adjust the index to be cyclical, not required if let count = data?.endIndex { if count == 1 && index != 0 { return nil } if index < 0 { index += count } index %= count } viewController.view.tag = index viewController.record = data?[index] return viewController } func pageViewController(pageViewController: UIPageViewController, viewControllerAfterViewController viewController: UIViewController) -> UIViewController? { let index = viewController.view?.tag ?? 0 return viewControllerWithIndex(index + 1) } func pageViewController(pageViewController: UIPageViewController, viewControllerBeforeViewController viewController: UIViewController) -> UIViewController? { let index = viewController.view?.tag ?? 0 return viewControllerWithIndex(index - 1) } func presentationCountForPageViewController(pageViewController: UIPageViewController) -> Int { return countAndSetupPageControl() } func presentationIndexForPageViewController(pageViewController: UIPageViewController) -> Int { return viewController?.view.tag ?? 0 } }
Now for the "subzone" you will need to implement a ChildViewController . If you are using storyboards, you can simply drag and drop the Container View and place the PageViewController in the built-in view controller, otherwise you need to add PageViewController.view as a PageViewController.view and set the frame in the middle.
More information can be found in the documentation for Apple , but basically you MUST call these methods:
addChildViewController(pageViewController) view.addSubView(pageViewController.view) pageViewController.view.frame = ... // This is your "sub-area" pageViewController.didMoveToParentViewController(self)
Yariv source share