CALayer renderInContext iOS7

2 calayer ios6 uigraphicscontext ios7

I'm rendering multiple layers to get one final image. One of the images contains a face, and another one contains a background with a transparent gradient around the face so that the real background is hidden. In iOS6 it works perfectly but it is creating a weird effect with the transparent gradient in iOS7.

The code:

CGRect rect = [[UIScreen mainScreen] bounds];
UIGraphicsBeginImageContext(rect.size);

CGContextRef context = UIGraphicsGetCurrentContext();

[faceImageView.layer renderInContext:context];
[fakeBackgroundImageView.layer renderInContext:context];

UIImage *img = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
Run Code Online (Sandbox Code Playgroud)

The results in iOS6 and iOS7:

iOS6的

IOS 7

小智 6

好的,解决方案是改变这一行:

UIGraphicsBeginImageContext(rect.size);
Run Code Online (Sandbox Code Playgroud)

对于这一个:

UIGraphicsBeginImageContextWithOptions(rect.size, TRUE, [[UIScreen mainScreen] scale]);
Run Code Online (Sandbox Code Playgroud)

现在它也适用于iOS7