سؤال

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?

هل كانت مفيدة؟

المحلول

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

نصائح أخرى

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

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];
    }
}
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top