I'm trying to change UIPageViewController
shadow color while doing a flip animation.
But always it displaying white color only.
How to change a color of flip side background color white to other colour like (black or sephia). iBook is doing same thing.
I mention that below image have white bg that color i would to change.
Screenshot:
I've been trying to do the same thing for some time now and I finally figured it out. Turns out you can't set the background color to other colors, but you can provide another view that UIPageViewController will add to the back. And that's the secret here.
From Apple's 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 double sided property to yes and provide two viewControllers on 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 every new page you add. So, you need to provide the viewController you would normally return and also a new viewController that will be added to the back when doing the page turning animation.
It's up to you what your "BackViewController" will have. You can simply have a black view or if you want, you can take a screenshot of the front page, and get a mirrored image from it.
It's not hard once you understand how it works. The only problem I can see here is that when you add a black view or anything that has a black background, the shadow when turning the page becomes WHITE. I have no idea why, but I've seen this happening on a lot of different apps, so I guess to Apple this is the normal behavior. But it looks really weird.
EDIT:
I've added a sample code so it is easier to understand. https://github.com/mattabras/DoubleSidedPageViewController
Abras
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With