What are Layers good for? What could I do with adding an Layer, and why should I think about Layers?

前端 未结 2 1620
半阙折子戏
半阙折子戏 2021-02-06 16:13

I am wondering what makes Layers different from Views, when every View comes along with it\'s own Layer. Maybe I am wrong with that. But then: What are these Layers good for?

2条回答
  •  爱一瞬间的悲伤
    2021-02-06 17:13

    On the iPhone, there's not a significant performance difference between using UIViews and CALayers, in my experience. The Mac is a different story, with NSViews being significantly more heavyweight.

    Dealing with CALayers (or at least a view's layer backing) is sometimes necessary for complex animations, particularly keyframe animations or movement along paths.

    Additionally, CALayers can be used to create platform-independent (Mac and iPhone) custom user interfaces. UIViews are very different from NSViews, but CALayers are identical between the iPhone and Mac OS X Leopard (aside from a few properties that are missing on the iPhone). I've used CALayers to share UI code between an iPhone application and its Mac counterpart.

提交回复
热议问题