开发者

NSAnimation looping

I've a view that starts an animation when the user drag files on it. The animation shows the files' relative icon (inside an NSImageView Ivar of the NSAnimation custom class) going bigger while fading.

If I loop the animation inside a s开发者_JS百科tandard loop like:

CustomAnimation *animation = [[CustomAnimation alloc] initWithDuration: 2.0 animationCurve: NSAnimationLinear]

NSimage *icon;

for (NSString *filename in filenames) {
    icon = [[NSWorkspace sharedWorkspace] iconForFile: filename];
    NSImageView *myImageView = [[NSImageView alloc] initWithFrame: theFrame];
    [myImageView setImage: icon];
    [animation setImageView: myImageView];
    [animation startAnimation];
}

The loop is too fast and the animations looks like if it were fired almost together (obviously).

What do you think is the best approach to loop an animation several times controlling the delay between the start of one animation and the subsequent?


The reason why your animation blaze by (except perhaps the last one) is that at each iteration your are "overwriting" the previous animation with a new one.

This post on chaining core animations together should do the trick if the idea is to have each animation take the full 2s. You can event add gaps between the animations.

-- Edit --

@Richard that's my mistake, I've misread the question.

A look at the documentaton for NSAnimation suggests that you might use startWhenAnimation:reachesProgress: to chain your animations though.


You can use NSTimer for that purposes.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜