NSAnimation 循环

发布于 2024-12-03 04:51:21 字数 646 浏览 1 评论 0原文

我有一个视图,当用户在其上拖动文件时启动动画。动画显示文件的相对图标(在 NSAnimation 自定义类的 NSImageView Ivar 内)在淡入淡出时变大。

如果我在标准循环内循环动画,例如:

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];
}

循环太快,并且动画看起来几乎是一起触发的(显然)。

您认为多次循环动画以控制一个动画开始与下一个动画之间的延迟的最佳方法是什么?

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 standard 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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

別甾虛僞 2024-12-10 04:51:21

你的动画之所以如此火爆(也许除了最后一个)是因为在每次迭代时你都会用新的动画“覆盖”以前的动画。

如果我们的想法是让每个动画都采用,这篇关于将核心动画链接在一起的文章应该可以解决问题完整的2秒。您可以在动画之间添加间隙。

- 编辑 -

@Richard 这是我的错误,我误读了这个问题。

查看 NSAnimation 的文档表明您可以使用 startWhenAnimation:reachesProgress: 来链接动画。

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.

愿与i 2024-12-10 04:51:21

您可以使用 NSTimer 来实现此目的。

You can use NSTimer for that purposes.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文