如何在确定的 NSProgressIndicator 上停止动画?

发布于 2024-10-16 15:17:43 字数 404 浏览 2 评论 0原文

NSProgressIndicator 允许在 isInstituteate == YES 时使用 stopAnimation:,但是如何停止确定进度条的动画呢?

对于上下文,我尝试执行此操作的进度条是 NSView 的子级,它本身是 NSMenuItem 的 view 属性。向 setAnimationDelay: 发送高得离谱的数字可以满足我的要求,但只是暂时的——当父菜单关闭并重新打开时,进度条会再次呈现动画。

(可能是不必要的免责声明:我发誓这是一个合法的用例;我必须能够直观地(即:不使用文本)显示长时间运行的任务的进度,这些任务可能会暂停并重新启动- 根据后端的需要开始。除非附有出色的替代建议,否则不会接受归结为“UI 设计:你做得很好”的答案。

NSProgressIndicator allows stopAnimation: when isIndeterminate == YES, but how does one stop the animation for determinate progress bars?

For context, the progress bar I am trying to do this with is a child of an NSView, which itself is the view property of an NSMenuItem. Sending ridiculously high numbers to setAnimationDelay: does what I want, but only temporarily -- when the parent menu is closed and re-opened, the progress bar is animated again.

(Possibly unnecessary disclaimer: I swear this is a legit use case; I have to be able to visually (i.e.: without using text) display the progress of very-long-running tasks which may pause and re-start as needed by the backend. Answers which boil down to "UI design: ur doin it rong" will be not be accepted unless accompanied by a brilliant alternative suggestion. ;) )

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

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

发布评论

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

评论(2

想挽留 2024-10-23 15:17:43

像这样子类 NSProgressIndicator ,它也适用于 Lion:

@interface UnanimatedProgressIndicator : NSProgressIndicator {
@private
    BOOL    isAnimating;
}
@end

@interface NSProgressIndicator (HeartBeat)
- (void) heartBeat:(id)sender;      // Apple internal method for the animation
@end

@implementation UnanimatedProgressIndicator

- (void) startAnimation:(id)sender
{
    isAnimating = YES;
    [super startAnimation:sender];
}

- (void) stopAnimation:(id)sender
{
    isAnimating = NO;
    [super stopAnimation:sender];
}

- (void) heartBeat:(id)sender
{
    if (isAnimating)
        [super heartBeat:sender];
}

@end

Subclass NSProgressIndicator like this, it also works with Lion:

@interface UnanimatedProgressIndicator : NSProgressIndicator {
@private
    BOOL    isAnimating;
}
@end

@interface NSProgressIndicator (HeartBeat)
- (void) heartBeat:(id)sender;      // Apple internal method for the animation
@end

@implementation UnanimatedProgressIndicator

- (void) startAnimation:(id)sender
{
    isAnimating = YES;
    [super startAnimation:sender];
}

- (void) stopAnimation:(id)sender
{
    isAnimating = NO;
    [super stopAnimation:sender];
}

- (void) heartBeat:(id)sender
{
    if (isAnimating)
        [super heartBeat:sender];
}

@end
茶色山野 2024-10-23 15:17:43

使用与前面描述的相同的方法解决了这个问题,但做了一个小改动。

当菜单的委托收到 menuNeedsUpdate: 时,我将 setAnimationDelay: (使用足够大的数字作为参数)发送到每个进度条。现在它工作可靠,所以我对此很满意。

Solved the problem using the same approach as described previously, with one small change.

When the menu's delegate receives menuNeedsUpdate:, I send setAnimationDelay: (with the sufficiently huge number as the arg) to each progress bar. This is working reliably now, so I'm happy enough with it.

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