CAShaperLayer -renderInContext不起作用? [英] CAShaperLayer -renderInContext Doesn't Work?

查看:74
本文介绍了CAShaperLayer -renderInContext不起作用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我可以使用以下代码从Core Animation层创建UIImage:

I am able to create a UIImage from a Core Animation layer using the following code:

- (UIImage*)contentsImage;
{
   UIGraphicsBeginImageContext([self bounds].size);
   [self renderInContext:UIGraphicsGetCurrentContext()];
   UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
   UIGraphicsEndImageContext();

   return image;
}

此代码在我的CALayer派生类中。我遇到的问题是,我有两个CAShapeLayers,它们是我图层的子图层,无法渲染到生成的图像。如果我将标准CALayers添加为子级,它们会变得很好。苹果文档说:

This code is in my CALayer derived class. The issue I am running into is that I have two CAShapeLayers that are child layers of my layer that do not get rendered to the resulting image. If I add standard CALayers as children they get rendered fine. The Apple docs say:


将接收器及其子层
渲染到指定的上下文中。

Renders the receiver and its sublayers into the specified context.

它也说它从iPhone OS 2.0开始就可用。

It also says that it's been available since iPhone OS 2.0. Wondering if there is something I'm missing or if I should file a radar.

任何想法可能会阻止孩子CAShapeLayers吸引到图像吗?

Any ideas what might keep the child CAShapeLayers from getting drawn to the image?

谢谢。

推荐答案

CALayer机制调用renderInContext创建其位图内容属性。但是在CAShapeLayer中,路径属性实际上并未呈现为其内容,如标题中的此注释所示:

The CALayer machinery calls renderInContext to create its bitmapped contents property. But in a CAShapeLayer, the path property is not actually rendered to its contents as seen by this note in the header:


整体是图层内容与其
第一子层之间的复合

The shape as a whole is composited between the layer's contents and its first sublayer.

这足以说明renderInContext赢得了实际上不会将CAShapeLayer路径呈现到您的上下文中。不过,我实际上还没有亲自尝试过。

It stands to reason that renderInContext won't actually render the CAShapeLayer path onto your context. I haven't actually tried this out for myself however.

这篇关于CAShaperLayer -renderInContext不起作用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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