【问题标题】:Can a CGImage be added to the contents property of a CAShapeLayer?CGImage 可以添加到 CAShapeLayer 的内容属性中吗?
【发布时间】:2010-07-02 16:30:37
【问题描述】:

我有一个带有 layerClass 覆盖的自定义视图,例如:

+ (Class) layerClass
{
    return [CAShapeLayer class];
}

我希望能够像这样将 CGImage 添加到内容属性:

- (void) animateView
{
    UIImage *layerImage = ...;
    CAShapeLayer *layer = (CAShapeLayer *)self.layer;
    layer.contents = layerImage.CGImage;

    //....Do other fun animations here
}

我是否需要设置其他属性,或者其他方式来获取形状层以渲染图像内容以进行动画处理?

【问题讨论】:

    标签: iphone core-animation core-graphics calayer cashapelayer


    【解决方案1】:

    我认为不会:CAShapeLayer 几乎只是用于渲染矢量路径。您是否尝试过创建通用图层,将图像指定为其内容,并将其添加为形状图层的子图层?

    【讨论】:

    • 这似乎也不起作用。我将采用不同的方法来解决这个问题,但我认为这会容易得多......我想不会。
    • 我知道您可以将 CGImageRef 分配给 CALayer 的 contents 属性。也许图像的格式不受支持?
    猜你喜欢
    • 2010-11-19
    • 2021-03-24
    • 2020-05-04
    • 2022-12-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-11-01
    • 1970-01-01
    相关资源
    最近更新 更多