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 9170605
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T16:02:51+00:00 2026-06-17T16:02:51+00:00

I am using block code to create a horizontal progress bar which reflects some

  • 0

I am using block code to create a horizontal progress bar which reflects some data, data could be anything. It just takes a min value, a max value, and a current value which allows me to set up the animation, i.e min value 0, max value 100, currently value 50, the progress bar will fill up by 50%. I have a progress bar container with a view inside it, the view gets stretched while animating.

I have got the animation part working fine using block code, i.e.

[UIView animateWithDuration:3.0
                              delay:0.0f
                            options:UIViewAnimationCurveEaseInOut
                         animations:^(void)
         {
             progressView.frame = CGRectMake(progressView.frame.origin.x,progressView.frame.origin.y,iWidth,progressView.frame.size.height);

         }
                         completion:^(BOOL finished)
         {

         }]; 

What I want to do is while this is animating, to slowly change the gradient by inserting sublayers, quick example

    (This method will be called on a timer, the idea is to slowly change the gradient
    after 0.5 seconds for example)
    CAGradientLayer *testLayer = [BackgroundLayer customGradient:iRedValue :iGreenValue :0];
    testLayer.frame = progressView.bounds;
    [progressView.layer insertSublayer:testLayer atIndex:1];

(The background layer is just a custom class I have which allows users to create a custom gradient colour using RGB values). The idea is, I would keep inserting sub layers slowly changing the gradient as the progressView finishes animating. The idea is that the view starts off one colour, say green, and the further along the bar animates, it changes colour to amber, then red if it reaches maximum.

When I add the sublayer the animation just jumps to the end, because testLayer takes on the width of the progressView after it is finished animating, and adds it. I want this to happen slowly over the course of the animation.

Any ideas on how I would go about doing 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-06-17T16:02:52+00:00Added an answer on June 17, 2026 at 4:02 pm

    Small example of Animationg colors of a CAGradientLayer

    @interface GradientAnimationView : UIView
    
    @end
    
    @implementation GradientAnimationView {
        NSArray *_colorsFirst;
        NSArray *_colorsSecond;
        NSArray *_currentColor;
    }
    
    + (Class)layerClass {
        return [CAGradientLayer class];
    }
    
    - (id)initWithFrame:(CGRect)frame
    {
        self = [super initWithFrame:frame];
        if (self) {
            CAGradientLayer *layer = (CAGradientLayer *)[self layer];
            _colorsFirst = @[(__bridge id)[[UIColor blueColor] CGColor], (__bridge id)[[UIColor greenColor] CGColor]];
            _colorsSecond = @[(__bridge id)[[UIColor redColor] CGColor], (__bridge id)[[UIColor yellowColor] CGColor]];
            _currentColor = _colorsFirst;
            [layer setColors:_colorsFirst];
        }
        return self;
    }
    
    - (void)animateColors {
        if (_currentColor == _colorsSecond) {
            _currentColor = _colorsFirst;
        } else {
            _currentColor = _colorsSecond;
        }
    
        CABasicAnimation *anim = [CABasicAnimation animationWithKeyPath:@"colors"];
        anim.fromValue = [[self layer] valueForKey:@"colors"];
        anim.toValue = _currentColor;
        anim.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
        anim.duration = 0.4;
        anim.delegate = self;
    
        [self.layer addAnimation:anim forKey:@"colors"];
    }
    
    - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
        [self animateColors];
    }
    
    - (void)animationDidStop:(CAAnimation *)theAnimation finished:(BOOL)flag {
        CAGradientLayer *layer = (CAGradientLayer *)[self layer];
        [layer setColors:_currentColor];
    }
    
    @end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Im trying to create counter that using shared block memory, just look code: $i=0;
I am trying to create some dynamic sql using the following code block firstSqlStatement
I am using the below code to block the taskbar which is working perfectly.
I have the following block of jQuery code that I'm using to copy some
Using this block of code to create an overlay and a box. problem: the
I'm using Drupal 7. And i created a block and embed this code: $contents
I am using this block of code to mimic the way files are uploaded:
I seem to be using this block of code alot in Python. if Y
I am trying to code AES using Cipher Block Chaining(CBC) mode. I am pretty
Today I was met the following code block: #include <iostream> using namespace std; char

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.