0

Currently I have the following code to update the NSLevelindicator:

[self.headerIndicator selfFloatValue:heightValue]

Is there any way to animate the the level indicator between values when they update?

BlindingDawn
  • 274
  • 1
  • 4
  • 19

4 Answers4

1

read this answer to animating sliders. i haven't tried it with level indicators but from the API docs it seems a viable option. the source code there can easily be adapt: NSSlider animation

Community
  • 1
  • 1
Daij-Djan
  • 49,552
  • 17
  • 113
  • 135
1

I have tried this code and it works fine:

Swift: self.CpuLevel.maxValue = Double(value)

0

If [[[self.headerIndicator] animator] setFloatValue:heightValue]; doesn't work, you must add the capability yourself. See NSAnimatablePropertyContainer.

Joshua Nozzi
  • 60,946
  • 14
  • 140
  • 135
  • animator doesn't work. Do you have any sample code I could use using NSAnimatablePropertyContainer? – BlindingDawn Sep 14 '12 at 13:43
  • Have you read the docs? Googled for examples? Tried anything? – Joshua Nozzi Sep 14 '12 at 14:31
  • Well the docs for NSAnimatablePropertyContainer (how I read it) apply to animating it with graphics, not with values or animating the values from one point to another. I did find [LERP](http://stackoverflow.com/questions/1820862/obj-c-linear-interpolation-between-two-numbers) that will give you a value in the middle of two values. I'm now trying to figure out a way of looping through a small curve and change the the value of NSLevelIndicator within that curve. – BlindingDawn Sep 14 '12 at 15:02
0

You could write your own method, something like this to change the level. The math in there tries to keep the total "animation" time equal regardless of how big the transition is from the old value to the new (around 1 second with these values).

-(void)updateLevel:(NSNumber *) newLevelNum {
    float currentLevel = self.level.floatValue;
    float newLevel =  newLevelNum.floatValue;
    if (self.delay == 0.0) // self.delay is a float property set to 0.0 elsewhere
        self.delay = .2 /(newLevel - currentLevel);
    [self.level setFloatValue:currentLevel + .2];
    if (self.level.floatValue - newLevel < .01){
        [self performSelector:@selector(updateLevel:) withObject:newLevelNum afterDelay:self.delay];
    }
}
rdelmar
  • 103,982
  • 12
  • 207
  • 218