0

It's relatively easy to animate the path of a CAShapeLayer.

( Great article on that: https://stackoverflow.com/a/36461202/294884 )

let shapeLayer = CAShapeLayer()
shapeLayer.path = .. some bezier
... CABasicAnimation(keyPath: "path")

But is it actually possible to animate layer.mask in a UIView?

Recall that

  1. The actual layer.mask of a UIView will actually mask subviews of the UIView.

  2. a CAShapeLayer with a path does not mask subviews of the UIView; it just masks itself and creates a pretty picture there on that view.

Can you animate a UIView's .layer.mask ?

Fattie
  • 27,874
  • 70
  • 431
  • 719

1 Answers1

1

Yes you can. I created a whole series of "wipe" transition animations doing that. You just make the CAShapeLayer the mask, and animate the path of that mask's shape layer. (In my case I animated the start or end property of the path.)

The thread is pretty old at this point, and the code is written in Objective-C, but here is a SO thread explaining how to do create a "clock wipe" animation using a CAShapeLayer as a layer mask.

How do you achieve a "clock wipe"/ radial wipe effect in iOS?

Duncan C
  • 128,072
  • 22
  • 173
  • 272
  • Ah I've got it now @DuncanC ! thanks! I see what you're saying. If you set the .mask of the view as a layer - and you animate that layer - it apparently "knows" that means to animate the .mask of the view! Thanks! – Fattie Aug 13 '19 at 20:48