Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to change shadow background white to other colors

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: enter image description here

like image 474
Nishu Avatar asked Sep 12 '12 05:09

Nishu


1 Answers

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

like image 162
Abras Avatar answered Oct 14 '22 03:10

Abras