cocoaheads-coreanimation-samplecode icon indicating copy to clipboard operation
cocoaheads-coreanimation-samplecode copied to clipboard

Why not use Arc for this?

Open dissidently opened this issue 12 years ago • 4 comments

Sorry if an issue is the wrong way to ask this, but why do you not use the arc feature of Core Animation? Something like a CAShapeLayer with a CGPath drawn with CGPathAddArc.

dissidently avatar Mar 04 '14 00:03 dissidently

I'm sorry, this sample code is almost two years old and contains five different projects. What project and what part of the code are you referring to?

d-ronnqvist avatar Mar 04 '14 08:03 d-ronnqvist

Sorry! Pie Chart Animation Progress project. You draw the pie (a circle and its progress states) by rounding the corners of a square rectangle until its a circle and then somehow transferring this to a UIBezier that you then part draw from 1 to 0 to animate the pie segment.

dissidently avatar Mar 04 '14 08:03 dissidently

You could just as well use an arc and the CGPath API right away. Since this is sample code which focuses on the stroke animation I tried to keep the path creation as simple and easy to understand as possible. I believe that the UIBezierPath API looks friendlier when you see it the first time and that since people often use cornerRadius to create circular layers, a rounded rectangle is a very familiar concept.

If I would write a similar component for myself or with the purpose of being a reusable control (as opposed to sample code for learning purposes) I would probably have used CGPathAddArc directly.

d-ronnqvist avatar Mar 04 '14 09:03 d-ronnqvist

Thanks, very much! I thought there might be some intrinsic performance advantage I'm not aware of as I'm very new to Core Animation. Thanks for your time, and for this and many other of your efforts on SO. They've been incredibly insightful.

dissidently avatar Mar 04 '14 09:03 dissidently