views:

336

answers:

1

I have been searching around, but there seems no good answer for this simple question. So I am asking again: how to animate line-drawing in iphone dev?

Basically what I want is something like this:

@implementation MyUIView

- (void) triggerLineDrawing: (CGPathRef) path {
   ...
   // animate line drawing here
   // and the line should disappear automatically after a few seconds
}

Can it be done?

+1  A: 

You can't do it automatically, only bu hand. To do it manually you should do something like this:

  • create array of your line points.
  • start an NSTimer, that will fire for example, 15 times a second.
  • every tick of a timer you have to find out, what part of the line you need to draw (look at linear interpolation)
  • update path that you draw (only with needed points + one last point that moves)
  • send setNeedsDraw message to view.

You can vary interpolation algorythm, speed of line drawing etc. to get the effect that you need.

Alexander Babaev