【问题标题】:How to render a UIView hierarchy into a CGContext with CoreAnimation composition model如何使用 CoreAnimation 组合模型将 UIView 层次结构渲染到 CGContext
【发布时间】: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


【解决方案1】:

很抱歉,但你没有办法做到这一点。

图层的当前动画状态是私有的,无法访问。 这可能是由于性能原因。启用对可动画属性的即时值的访问以及使结构中的值与 Core Graphics 兼容会降低图形性能。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-08-30
    • 1970-01-01
    • 2020-10-02
    • 1970-01-01
    • 1970-01-01
    • 2014-03-01
    • 1970-01-01
    相关资源
    最近更新 更多