UIView & NSView & CALayer
Abozaid Ibrahim
Staff iOS Engineer | Building Scalable Mobile Apps | Mobile Lead | Mentor
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?
- 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.
- working directly with CALayers doesn't give you significant performance advantages over UIViews