Core Animation: Using Layer Masks

Using a mask on a core animation layer is quite easy. This example does the following:

  • Creates an NSImage by filling an NSBezierPath.
  • Converts the NSImage into a CGImageRef
  • Creates three CALayers
    • one to show what the mask looks like
    • one for the layer that will have
    • one for our our mask

Voila!

A Core Animation Mask

You can grab the kode here.

Tags:

2 Responses to “Core Animation: Using Layer Masks”

  1. perlmunger Says:

    Did you ever figure out if there was a simple way to invert the mask?

    Thanks.

    -Matt

  2. Matthieu Cormier Says:

    I never even considered that question. It should be easy enough to do though. Write a function that takes an Image as input. If the pixel is transparent make it solid, and vice versa. Return the resultant image.