2010-12-22 45 views
2

我想将UIView层次结构呈现为CGContext或最终呈现为UIImage。某些子视图具有3D变换,其中renderInContext:会随着阴影和其他一些CALayer属性而被忽略。如何使用CoreAnimation组合模型将UIView层次结构呈现为CGContext

从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转换?

+0

你有没有得到这个问题的地方? – kevboh 2011-06-20 02:15:20

回答

0

我很抱歉,但没有办法如何做到这一点。

图层的当前动画状态是私有的,无法访问。 这可能是由于性能原因。启用访问动画属性的立即值,并具有与核芯显卡兼容结构的值会降低显卡的性能。