如何将阴影背景改为其他颜色

我试图改变UIPageViewController阴影颜色,同时做一个翻转animation。 但总是只显示白色。 如何将翻转侧背景颜色的颜色改变为其他颜色,如(黑色或sephia)。 iBook正在做同样的事情。

我提到,下面的图像有白色的颜色,我会改变。

截图: 在这里输入图像说明

 - (void) renderPageAtIndex:(NSUInteger)index inContext:(CGContextRef)ctx { UIImage *image = [images objectAtIndex:index]; CGRect imageRect = CGRectMake(0, 0, image.size.width, image.size.height); CGAffineTransform transform = aspectFit(imageRect, CGContextGetClipBoundingBox(ctx)); CGContextConcatCTM(ctx, transform); CGContextDrawImage(ctx, imageRect, [image CGImage]); } 

我一直在尝试做同样的事情,现在我终于明白了。 原来,你不能设置其他颜色的背景颜色,但你可以提供另一个视图,UIPageViewController将添加到后面。 这就是这里的秘密。

从苹果的文档:

 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. 

所以,基本上,您需要将双侧属性设置为yes,并在两个数据源方法上提供两个viewController:

 - (UIViewController *)pageViewController:(UIPageViewController *)pageViewController viewControllerBeforeViewController:(UIViewController *)viewController; - (UIViewController *)pageViewController:(UIPageViewController *)pageViewController viewControllerAfterViewController:(UIViewController *)viewController; 

每添加一个新页面,每个方法都会被调用两次。 所以,你需要提供你通常会返回的viewController,并且还需要一个新的viewController,在做页面animation的时候将会添加到后面。

这取决于你的“BackViewController”。 您可以简单地使用黑色视图,或者如果需要,可以截取首页的截图,并从中获取镜像图像。

一旦你了解它的工作原理,这并不难。 我在这里可以看到的唯一问题是,当您添加黑色视图或任何具有黑色背景的内容时,翻页时的阴影将变为白色。 我不知道为什么,但是我看到这发生在很多不同的应用程序上,所以我猜苹果这是正常的行为。 但它看起来很奇怪。

编辑:

我已经添加了一个示例代码,以便更容易理解。 https://github.com/mattabras/DoubleSidedPageViewController

阿巴拉

在页面控件可选页面可见性的情况下 –

UIPageControl默认不支持这个。 您必须创build自己的页面控件,并自行完成绘图。