NSView and CALayer

I recently come across animation problem in building macOS app. I was not able to display a transformed layer properly. Things went funky. Thus I decided to spend some time in reading the documentation once again.

It brings me to the followings:

They have a relationship like this:

NSView sits inside AppKit Framework, it can become a layer-backed view and add hardware support to render graphics.

Important Learnings

  1. Once CALayer is used, the visual is rendered by hardware. That said, pure NSView is processed by CPU
  2. NSView has a flipped coordinate system as compared to UIView. Point (0, 0) in NSView refers to bottom-left corner
  3. AppKit and NSView do not provide easy way to animate content
  4. Core Animation is actually the same on macOS and iOS. Yet most people on iOS would use UIView to animate
  5. Core Animation makes use of keyPath to define what to animate
  6. CATransaction can be used to animate several properties explicitly
  7. After the animation is done, the animated property will still keep at the original value, thus the visual will jump back at the end of animation
  8. Set the animated property to the end value after animation code
  9. Add subview to the view hierarchy before setting anchor point and other transformations
  10. CATransform itself is a value, not an animation. Set it and the layer will transform to that particular value.

I have worked on a sample project to demonstrate the learnings above through a 3D transform along x-axis.