开发者

What's the best way to do looping animations?

The key word is looping. I'm thinking I would have two functions for an animation, such as a pulse. Is this the best way 开发者_C百科to make it loop?

-(void)animationPart1 {

    //Do first half of animation here, pulse in, the animation is 0.3 seconds long
    [NSTimer scheduledTimerWithTimeInterval:0.3 target:self selector:@selector(animationPart2) userInfo:nil repeats:NO];

}

-(void)animationPart2 {

    //Do second half of animation here, pulse out, the animation is 0.3 seconds long
    [NSTimer scheduledTimerWithTimeInterval:0.3 target:self selector:@selector(animationPart1) userInfo:nil repeats:NO];

}

I'm new to animations, so thanks for your help!


If you use that approach, I think your should set "repeats" to "YES" and then you don't have to create a recursive loop like that.

Aside from that, without knowing precisely what you are attempting to animate, I do think there are a number of ways to approach animation such as Core Animation's "CABasicAnimation" which has a number of different ways to animate various things (see examples):

http://www.cimgf.com/2009/10/20/marching-ants-with-core-animation/

If you are doing very heavy animation such as a game, then use Cocos2D, it rocks.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜