Is it possible to animate something that you have drawn using core graphics in a UIView’s drawRect method?
Say for example I have created a zigzag line by stroking a path. What if I want to animate something like the position of an individual point in that path? If my UIView has the properties animatedPointX and animatedPointY which are used to draw my point, can I somehow animate my zigzag line by changing these properties? Is something like this possible with Core Graphics?
Every animation example and tutorial I have found deals with animating an entire view as a whole. I cant seem to find anything about animating custom properties of your drawing/layer.
If you want to animate the graphics that you draw in
drawRect:, you need to periodically update the variables that control what you draw and sendsetNeedsDisplayto the view.Apple recommends using a
CADisplayLinkobject to periodically notify yourself that it’s time to update and redraw.You can see an example of the use of
CADisplayLinkto trigger the update andsetNeedsDisplayin theARView.mfile of thepARksample app.