简体   繁体   English

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

[英]How to stop the animation on a determinate NSProgressIndicator?

NSProgressIndicator allows stopAnimation: when isIndeterminate == YES , but how does one stop the animation for determinate progress bars? NSProgressIndicator允许stopAnimation:isIndeterminate == YES ,如何停止动画以确定进度条?

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. 对于上下文,我要使用的进度条是NSView的子级,它本身就是NSMenuItem的view属性。 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. setAnimationDelay:发送高得离谱的数字setAnimationDelay:做我想做的事情,但只是暂时的-当父菜单关闭并重新打开时,进度栏会重新设置动画。

(Possibly unnecessary disclaimer: I swear this is a legit use case; I have to be able to visually (ie: 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. ;) ) (可能不必要的免责声明:我发誓这是一个合法的用例;我必须能够直观地 (即:不使用文本)显示非常长时间运行的任务的进度,这些任务可能会暂停并根据后端的需要重新启动。归根结底是“ UI design:ur doin it rong”的答案将不被接受,除非有出色的替代建议。

Subclass NSProgressIndicator like this, it also works with Lion: 像这样子类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

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. 当菜单的委托收到menuNeedsUpdate: ,我将setAnimationDelay:具有足够大的数字作为arg)发送到每个进度栏。 This is working reliably now, so I'm happy enough with it. 现在,它可以可靠地工作,因此我对此感到满意。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM