How to change the hue of white to other colors

I am trying to change the shadow color of a UIPageViewController while performing a flip animation. But always it has only white color. How to change the color of the background color of the running side white to another color (black or sepia). iBook does the same.

I mention that below the image has white bg, which color I would change.

Screenshot: enter image description here

+6
source share
3 answers
 - (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]); } 
0
source

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

+7
source

In case of choice of color of visibility of page pagecontrol -

UIPageControl does not support this by default. You must create your own page control and make the drawing yourself.

-2
source

Source: https://habr.com/ru/post/925191/


All Articles