Can a CGImage be added to the contents property of a CAShapeLayer?

别来无恙 提交于 2020-01-06 18:08:36

问题


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?


回答1:


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?



来源:https://stackoverflow.com/questions/3167493/can-a-cgimage-be-added-to-the-contents-property-of-a-cashapelayer

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!