0

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. ;) )

jensck
  • 154
  • 1
  • 11
  • Is your progress indicator also showing changes in its value apart from animating? [Mine is doing neither...](http://stackoverflow.com/questions/23833929/nsprogressindicator-in-nsmenuitem-not-updating-on-second-display) – Frog May 23 '14 at 23:11

2 Answers2

1

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
BeBa
  • 11
  • 1
0

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.

jensck
  • 154
  • 1
  • 11
  • This method **setAnimationDelay:** is deprecated in 10.5 and does not seem to work at all on Lion. I am not sure how this can be done now. – Peter Apr 07 '11 at 10:31
  • It works without complaint when using bindings to set the delay. I don't have Lion though, so I have no idea if that will work there. – jensck Apr 13 '11 at 14:47