UIView & NSView & CALayer

UIView & NSView & CALayer



What's the difference?

On iOS, every UIView is backed by a Core Animation CALayer, so you are dealing with CALayers when using a UIView, even though you may not realize it. Unlike NSViews on the Mac, which evolved before Core Animation existed, UIViews are intended to be lightweight wrappers around these CALayers.

When to use CALayer on the Mac/iPhone?

One of the reasons you might want to build a user interface element with CALayers instead of UIViews is that it can be very easily ported to the Mac. 

Why do we keep using UIView?

  1. One thing UIViews provide over CALayers is built-in support for user interaction. They handle hit-testing on touches and other related actions that you would need to build yourself if managing a hierarchy of CALayers. It's not that hard to implement this yourself, but it is an extra code you'd need to write when building a CALayer-only interface.
  2. working directly with CALayers doesn't give you significant performance advantages over UIViews


要查看或添加评论,请登录

社区洞察

其他会员也浏览了