views:

762

answers:

1

How would you go about animating the drawing of a line in a UIView on the iPhone? Is this possible? It can be drawn but can it easily be animated so it appears to be hand drawn?

+1  A: 

There's no built-in way to do this no. You'd have to redraw the line repeatedly, interpolating between the start and end points using a timer callback to invalidate the view and trigger a redraw. Of course the redraw would have to draw everything in the area of the view bring redrawn which is potentially slow.

What I would do if I had a series of lines I wanted to draw over a period of time is to have two subviews - they would cover the same area and the top one would have a transparent background. Have the top one draw just the line that I am currently animating and when it's finished, draw the full length of it in the lower view. Then repeat, animating the next line in the top view.

U62
Could you give a more detailed example ? Some piece of code, or a link to demo code ?
Allisone