简体   繁体   English

是否可以在没有UIView的情况下显示CALayer?

[英]Is it possible to display an CALayer without an UIView?

As far as I can tell, I need an UIView (or subclass of UIView) to display an CALayer on screen, right? 据我所知,我需要一个UIView(或UIView的子类)才能在屏幕上显示CALayer,对吗?

Then, what's the point of using CALayer for saving memory? 那么,使用CALayer节省内存有什么意义呢? The only point I see is when I would add several sublayers to a CALayer. 我看到的唯一一点是何时将多个子层添加到CALayer。 Then those sublayers would not get copied 3 times for all the different tree types like presentation tree, render tree and so on. 然后,对于所有不同的树类型(如表示树,渲染树等),这些子层将不会被复制3次。 Is that right? 那正确吗?

You can add CALayer s as sublayers of another CALayer . 您可以将CALayer添加为另一个CALayer子层。 Each individual layer does not have to be backed by a view, but the root layer in the hierarchy must be backed by a UIView . 每个单独的层都不必由视图支持,但是层次结构中的根层必须由UIView支持。

The point is not to avoid having copies of the CALayer s, which are quite lightweight, but to avoid having copies of UIViews or, more specifically, the graphics contexts that back UIView s. 问题的关键不是避免的副本CALayer s,这是相当轻巧,但要避免副本UIViews或者更具体地说,图形上下文的备份UIView秒。 Those take up considerably more memory. 这些占用大量内存。

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

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