[英]How do I use CALayer renderInContext and keep the perspective transform?
How do I use CALayer renderInContext
and have the perspective transform (m34)
of the layer preserved? 如何使用CALayer renderInContext
并保留图层的透视变换(m34)
? It seems like this method assumes an Identity transform. 看起来这个方法假设一个Identity变换。 I have tried things like transforming the context, and this is fine for translation, rotation and scaling, but there does not seem to be a way to keep the perspective of the 3D transform. 我已经尝试过改变上下文这样的事情,这对于平移,旋转和缩放来说很好,但似乎没有办法保持3D变换的视角。
Maybe a better way to put this question: How do I apply a perspective while drawing to a CGContextRef? 也许是提出这个问题的更好方法:如何在绘制CGContextRef时应用透视图?
You might want to have a look at the method drawViewHierarchyInRect:afterScreenUpdates:
which is offered since iOS 7.0. 您可能希望查看方法drawViewHierarchyInRect:afterScreenUpdates:
自iOS 7.0以来提供的方法。 Applying the method to the view containing the CALayers will keep their 3D transformations. 将该方法应用于包含CALayers的视图将保持其3D变换。
Sample code: 示例代码:
BOOL opaqueBackground = YES;
UIGraphicsBeginImageContextWithOptions(theViewContainingYourCALayers.bounds.size, !opaqueBackground, 0);
[theViewContainingYourCALayers drawViewHierarchyInRect:theViewContainingYourCALayers.bounds afterScreenUpdates:YES];
[UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
As matt pointed out, relying solely on renderInContext:
is not possible since it disregards any transformation other than affine ones. 正如matt指出的那样,仅仅依赖于renderInContext:
是不可能的,因为它忽略了仿射之外的任何转换。
Late answer but I hope it still helps. 迟到的答案,但我希望它仍然有帮助。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.