CALayer vs. Layer-backed NSView 性能

CALayer vs. Layer-backed NSView Performance

我计划创建一个视图,其中可以包含数百个 CALayer 个对象,这些对象彼此相邻。因此,这必须尽可能高效。这些层不是很复杂。它们是不透明的,可以是文本或形状层。必须对这些层数进行布局。我会为此使用 CAConstraints

来自苹果文档:

Important: In OS X v10.8 and later, it is recommended that you minimize your use of layer hierarchies and just use layer-backed views. The layer redraw policies introduced in that version of OS X let you customize the behavior of your layer-backed views and still get the kind of performance you might have gotten previously using standalone layers.

我知道 CALayer 对象比视图更轻量级。我不确定为什么 我们应该使用图层支持的视图而不是直接使用图层。是为了便于使用自动布局,还是有更多与性能/内存相关的原因?我希望获得最佳性能,因为此代码将在 OS X 和 iOS.

上 运行

我应该走哪条路?自动布局和图层支持 NSViews 或自定义 CALayer 层次结构?

我决定使用图层支持视图。到目前为止,性能非常好。视图全部由 stackViews 布局。