【发布时间】:2011-05-29 06:04:33
【问题描述】:
我正在尝试将 UIView 层次结构呈现为 CGContext 或最终呈现为 UIImage。一些子视图具有 3D 变换,renderInContext: 会忽略它以及阴影和其他一些 CALayer 属性。
来自 CALayer.h:
/*
* WARNING: currently this method does not implement the full
* CoreAnimation composition model, use with caution. */
- (void)renderInContext:(CGContextRef)ctx;
在致电UIGraphicsBeginImageContext 后,我尝试了几种变体。
[self drawRect:[self bounds]];
[self.layer.delegate drawLayer:self.layer inContext:UIGraphicsGetCurrentContext()];
[self.layer renderInContext:UIGraphicsGetCurrentContext()];
[self.layer display];
视图层次结构最好在没有 3D 变换的情况下呈现。在最坏的情况下,图像是空的。我想在图像中得到一个有效的 alpha 通道,所以屏幕截图不太有效。
有没有办法在保留所有转换和图层属性的同时呈现 UIView 层次结构?
如果解决方案涉及递归迭代视图层次结构,将每个视图分别渲染为图像,并在合成步骤中为每个父视图应用所有变换和属性,那么如何应用 3D 变换?
【问题讨论】:
-
你遇到过这个问题吗?
标签: ios uiview core-animation render cgcontext