I have been trying to do the same for some time, and I finally figured it out. It turns out you cannot set the background color to other colors, but you can provide a different view that the UIPageViewController will add back. And this is the secret here.
From the Apple documentation:
Spine location Double sided What to pass UIPageViewControllerSpineLocationMid YES Left and Right Page. SpineLocationMin or SpineLocationMax YES Front and Back of the page. SpineLocationMin or SpineLocationMax NO Front page only.
So basically, you need to set the double sided property to yes and provide two viewControllers for both Data Source methods:
- (UIViewController *)pageViewController:(UIPageViewController *)pageViewController viewControllerBeforeViewController:(UIViewController *)viewController; - (UIViewController *)pageViewController:(UIPageViewController *)pageViewController viewControllerAfterViewController:(UIViewController *)viewController;
Each method will be called twice for each new page you add. Thus, you need to provide the viewController that you usually return, as well as a new viewController that will be added in the opposite direction when performing the page rotation animation.
It is up to you what your "BackViewController" will have. You can just have a black look or, if you want, you can take a screenshot on the first page and get a mirror image from it.
It is not difficult if you understand how it works. The only problem that I see here is that when you add a black look or something that has a black background, the shadow when turning the page turns white. I have no idea why, but I have seen this in different applications, so I think this is normal behavior. But it looks weird.
EDIT:
I added sample code to make it easier to understand. https://github.com/mattabras/DoubleSidedPageViewController
Abras
Abras source share