可以将 CGImage 添加到 CAShapeLayer 的内容属性中吗?

发布于 2024-09-08 04:27:57 字数 424 浏览 2 评论 0原文

我有一个带有 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
}

是否有其他我需要设置的属性,或其他方法来获取形状层以呈现内容的内容动画图像?

I have a custom view with a layerClass override like:

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

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

复古式 2024-09-15 04:27:57

我认为不是: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?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文