I would like to create a CALayer bezier path in a circle shape. And I would like to set it like it was a UIImageView (to be able to move it with animation etc.) Is it possible? If so how can I do it? Thank you.
I would like to create a CALayer bezier path in a circle shape. And
Share
I’m not sure what you mean by a “
CALayerbezier path” but you have a couple of options here:UIBezierPathmethods in thedrawRect:. This view can then be added to another view as a subview and animated using standard methods. However, you are warned that this may affect performance, (as it has to keep re-drawing) so if that does turn out to be a problem…UIImageView. Animate as in answer (1). This way you aren’t redrawing all the time so performance would be better, but try with option 1 first as it is simpler, and if you have simple drawing code it shouldn’t affect you too much.For option 2, you begin a graphics context using
UIGraphicsBeginImageContextWithOptions– you then do your drawing, and extract the image usingUIGraphicsGetImageFromCurrentImageContext, then end the context usingUIGraphicsEndImageContext. Those functions are all documented hereSample code to do this: