可以将CGImage添加到CAShapeLayer的content属性吗? [英] Can a CGImage be added to the contents property of a CAShapeLayer?

查看:105
本文介绍了可以将CGImage添加到CAShapeLayer的content属性吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I have a custom view with a layerClass override like:

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

我希望能够将CGImage添加到content属性,如下所示:

I want to be able to add a CGImage to the contents property like so:

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

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

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

Are there other properties I need to set, or other ways to get the shape layer to render the contents of the image for animation?

推荐答案

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

I would assume not: CAShapeLayer is pretty much just used to render a vector path. Have you tried creating a generic layer, assigning your image as its contents, and adding it as a sublayer of your shape layer?

这篇关于可以将CGImage添加到CAShapeLayer的content属性吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆