I'm trying to draw a simple shape as part of the interface of a game, and most tutorials use a UIBezierPath to define the path of a CAShapeLayer. However, I noticed that UIBezierPath already has an existing fill function.
This is probably a stupid question, but what is the difference between using that and using a separate CAShapeLayer to draw the path? Also, which one is better?
The "CA" in CAShapeLayer
stands for CoreAnimation.
If you wish to animate, move, manipulate, or well, anything else to a UIBezierPath
, you need to use a CALayer
(or it's subclass CAShapeLayer
).
UIBezierPaths are the correct thing to use if what you want is to simply "draw" - and it's usually done in draw(rect:)
. You can also "redraw" if you will.
But if you want persistence (and control) over a shape, turn that UIBezierPath
into a CAShapeLayer
.