开发者

How to animate line-drawing in iPhone development?

I have been searching around, but there seems no good answer for this simple question. So I am aski开发者_Python百科ng 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?


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜