How to change shadow background white to other colors

后端 未结 3 727
抹茶落季
抹茶落季 2020-12-30 10:55

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 s

3条回答
  •  情歌与酒
    2020-12-30 11:47

    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

提交回复
热议问题