Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7176399
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T16:29:56+00:00 2026-05-28T16:29:56+00:00

How can I create NSSlider animation when changing float value of it. I was

  • 0

How can I create NSSlider animation when changing float value of it. I was trying:

[[mySlider animator] setFloatValue:-5];

but that didn’t work.. just change the value without animation. So maybe someone knows how to do this?

Thanks in advance.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T16:29:57+00:00Added an answer on May 28, 2026 at 4:29 pm

    Ok – so this isn’t as quick and pretty as I hoped but it works.
    You can’t actually use animators and Core Animation on the slider knob – because Core Animation works only on layers and there’s no access to the knob values in the slider layer.

    So we have to resort instead to manually animating slider value.
    Since we’re doing this on a Mac – you can use NSAnimation (which isn’t available on iOS).

    What NSAnimation does is simple – it provide an timing/interpolation mechanism to allow YOU to animate (as opposed to Core Animation which also connects to the views and handles the changes to them).

    To use NSAnimation – you most commonly would subclass it and override setCurrentProgress:
    and put your logic in there.

    Here’s how I implemented this – I created a new NSAnimation subclass called NSAnimationForSlider

    NSAnimationForSlider.h :

    @interface NSAnimationForSlider : NSAnimation  
    {  
        NSSlider *delegateSlider;  
        float animateToValue;    
        double max;   
        double min;  
        float initValue;  
    }  
    @property (nonatomic, retain) NSSlider *delegateSlider;  
    @property (nonatomic, assign) float animateToValue;    
    @end  
    

    NSAnimationForSlider.m :

    #import "NSAnimationForSlider.h"
    
    @implementation NSAnimationForSlider
    @synthesize delegateSlider;
    @synthesize animateToValue;
    
    -(void)dealloc
    {
        [delegateSlider release], delegateSlider = nil;
    }
    
    -(void)startAnimation
    {
        //Setup initial values for every animation
        initValue = [delegateSlider floatValue];
        if (animateToValue >= initValue) {
            min = initValue;
            max = animateToValue;
        } else  {
            min = animateToValue;
            max = initValue;
        }
    
        [super startAnimation];
    }
    
    
    - (void)setCurrentProgress:(NSAnimationProgress)progress
    {
        [super setCurrentProgress:progress];
    
        double newValue;
        if (animateToValue >= initValue) {
            newValue = min + (max - min) * progress;        
        } else  {
            newValue = max - (max - min) * progress;
        }
    
        [delegateSlider setDoubleValue:newValue];
    }
    
    @end
    

    To use it – you simply create a new NSAnimationForSlider, give it the slider you are working on as a delegate and before each animation you set it’s animateToValue and then just start the animation.

    For example:

    slider = [[NSSlider alloc] initWithFrame:NSMakeRect(50, 150, 400, 25)];
    [slider setMaxValue:200];
    [slider setMinValue:50];
    [slider setDoubleValue:50];
    
    [[window contentView] addSubview:slider];
    
    NSAnimationForSlider *sliderAnimation = [[NSAnimationForSlider alloc] initWithDuration:2.0 animationCurve:NSAnimationEaseIn];
    [sliderAnimation setAnimationBlockingMode:NSAnimationNonblocking];
    [sliderAnimation setDelegateSlider:slider];
    [sliderAnimation setAnimateToValue:150];
    
    [sliderAnimation startAnimation];
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I can create a contact that is not mail enabled, but how do I
I can create a normal media player and its work fine. But i need
I can create a literal long by appending an L to the value; why
One can create an anonymous object that is initialized through constructor parameters, such as
I can create an array of buttons in Windows Form but how can i
I can create new Silverlight App with .NET RIA Services enabled. But when I
I can create .o file with g++ -c test.cpp -std=c++0x , but cant link
I can create an IISWebVirtualDir or IISWebVirtualDirSetting with WMI, but I've found no way
I can create a image folder when I create a category, so that I
How can create a mask input for number that have percent by jQuery? Do

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.