本文介绍了CALayer renderInContext iOS7的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在渲染多个图层以获得最终图像。其中一个图像包含一个面,另一个包含一个背景,在面部周围有透明渐变,以便隐藏真实背景。在iOS6中,它完美运行,但它在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.
代码:
CGRect rect = [[UIScreen mainScreen] bounds]; UIGraphicsBeginImageContext(rect.size); CGContextRef context = UIGraphicsGetCurrentContext(); [faceImageView.layer renderInContext:context]; [fakeBackgroundImageView.layer renderInContext:context]; UIImage *img = UIGraphicsGetImageFromCurrentImageContext(); UIGraphicsEndImageContext();iOS6和iOS7中的结果:
The results in iOS6 and iOS7:
推荐答案
好的,解决方法是改变这一行:
Ok, the solution was changing this line:
UIGraphicsBeginImageContext(rect.size);这个:
UIGraphicsBeginImageContextWithOptions(rect.size, TRUE, [[UIScreen mainScreen] scale]);现在它也适用于iOS7
Now it also works in iOS7
更多推荐
CALayer renderInContext iOS7
发布评论