简体   繁体   中英

UIBezierPath fill vs CAShapeLayer

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 .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM