简体   繁体   English

CALayer -drawInContext:和-renderInContext之间的区别是什么?

[英]What's the difference between CALayer -drawInContext: and -renderInContext:?

CALayer -drawInContext:和-renderInContext之间有什么区别?

When providing custom Quartz-drawn content to display within a CALayer, you can override -drawInContext: and do your custom drawing there. 提供自定义的Quartz绘制内容以在CALayer中显示时,您可以覆盖-drawInContext:并在那里进行自定义绘制。 This is similar to -drawRect: for a UIView or NSView. 这与-drawRect:类似-drawRect:对于UIView或NSView。 Alternatively, you can set another class to be the delegate of the CALayer and implement -drawLayer:inContext: to provide custom content to a standard CALayer. 或者,您可以将另一个类设置为CALayer的委托并实现-drawLayer:inContext:为标准CALayer提供自定义内容。

You don't override -renderInContext: , but instead you can call this on a layer to render it and all of its sublayers into a particular Core Graphics context. 您不要覆盖-renderInContext: ,而是可以在图层上调用它以将其及其所有子图层渲染​​到特定的Core Graphics上下文中。 Note that this won't render certain types of layers (like those with OpenGL content). 请注意,这不会呈现某些类型的图层(如具有OpenGL内容的图层)。 It also doesn't behave the way you'd expect when rendering into a PDF context, where the layers will come out as bitmapped rectangles instead of pure vector elements. 它也不会像渲染到PDF上下文时那样表现,其中图层将以位图矩形而不是纯矢量元素的形式出现。 To work around this, you might want to check out the Core Plot framework's CPTLayer implementation , where we bypass the normal rendering process in order to preserve the vectors in a PDF generated from our CALayer subclass. 要解决这个问题,您可能需要查看Core Plot框架的CPTLayer实现 ,我们绕过正常的渲染过程,以便保留从CALayer子类生成的PDF中的向量。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM