What are the differences between a UIView and a CALayer?

后端 未结 6 2192
天命终不由人
天命终不由人 2020-12-04 05:42

Both have most of the same attributes, both support different kind of animations, both represent different data. What are the differences between a UIView and a CALayer?

6条回答
  •  情书的邮戳
    2020-12-04 05:50

    UIView: Views have more complex hierarchy layouts. They can receive user interactions like taps, pinches, cliks and more. Working with UIViews happens on the main thread, it means it is using CPU power.

    CALayer: Layers on other hand have simpler hierarchy. That means they are faster to resolve and quicker to draw on the screen. There is no responder chain overhead unlike with views. Layers are drawn directly on the GPU. It happens on a separate thread without burdening the CPU.

    For more details: https://medium.com/@fassko/uiview-vs-calayer-b55d932ff1f5

提交回复
热议问题