开发者

How to render a UIView hierarchy into a CGContext with CoreAnimation composition model

I am trying to render a UIView hierarchy into a CGContext or ultimately a UIImage. Some of the child views have 3D transforms, which renderInContext: ignores along with shadows and some other CALayer properties.

From CALayer.h:

/*
 * WARNING: currently this method does not implement the full
 * CoreAnimation composition model, use with caution. */

- (void)renderInContext:(CGContextRef)ctx;

I have tried several variations after a call to UIGraphicsBeginImageContext.

[self drawRect:[self bounds]];
[self.layer.delegate drawLayer:self.layer inContext:UIGraphicsGetCurrentContext()];
[self.layer renderInContext:UIGraphicsGetCurrentContext()];
[self.layer display];

At best the view hierarchy renders without 3D transforms. At worst the image is empty. I would like to end up with a valid alpha channel in the image, so a screen captu开发者_如何转开发re does not quite work.

Is there a way to render a UIView hierarchy while preserving all transforms and layer properties?

If the solution involves recursively iterating the view hierarchy, rendering each view as an image separately, and applying all transforms and properties in a composition step for each parent view, how are 3D transforms applied?


I am sorry, but there is no way how you could do it.

The current animation state of a layer is private and cannot be accessed. This is probably due to performance reasons. Enabling the access to immediate values of animatable properties and having the values in structures compatible with Core Graphics would decrease graphics performance.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜