user1070255
user1070255

Reputation: 103

iPhone Core Graphics Animations

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.

Upvotes: 3

Views: 1729

Answers (1)

rob mayoff
rob mayoff

Reputation: 385998

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 send setNeedsDisplay to the view.

Apple recommends using a CADisplayLink object to periodically notify yourself that it's time to update and redraw.

You can see an example of the use of CADisplayLink to trigger the update and setNeedsDisplay in the ARView.m file of the pARk sample app.

Upvotes: 4

Related Questions