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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T09:28:18+00:00 2026-06-11T09:28:18+00:00

I have a view with a sublayer called specialLayer . Implicit animations for opacity

  • 0

I have a view with a sublayer called specialLayer. Implicit animations for opacity are disabled like this:

self.specialLayer.actions = [NSDictionary dictionaryWithObjectsAndKeys:
                                            [NSNull null], @"opacity", nil];

There are only two methods which access this sublayer.

- (void)touchDown {
    self.specialLayer.opacity = 0.25f;
}

- (void)touchUp {
    CABasicAnimation *animation = [CABasicAnimation animationWithKeyPath:@"opacity"];
    animation.fromValue = [NSNumber numberWithFloat:self.specialLayer.opacity];
    animation.toValue = [NSNumber numberWithFloat:1.0];
    animation.duration = 0.5;
    animation.removedOnCompletion = NO;
    animation.fillMode = kCAFillModeForwards;
    animation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseOut];
    [self.specialLayer addAnimation:animation forKey:@"opacity"];
}

This happens:

1) User presses a button down (holding) and -touchDown gets called. specialLayer’s opacity instantly becomes 0.25

2) User releases button and -touchUp gets called. specialLayer’s opacity animates back to 1.0

This sequence only works ONCE!

3) User presses a button down again (holding) and -touchDown gets called. But specialLayer’s opacity does not change on screen! Nothing happens even though self.specialLayer.opacity = 0.25f; gets called. Opacity appears to remain 1.0f.

4) User lifts finger up and -touchUp gets called. specialLayer’s opacity JUMPS to 0.25 and from there animates to 1.0f.

I checked with NSLog to make sure the methods get called in this order. They do.

When I uncomment the animation code and set the opacity directly to 1.0, subsequent direct opacity changes are effective immediately. It is definitely the CABasicAnimation which causes problems. Removing the code that disables implicit animations has no effect on this problem.

I can’t for the life of me figure out what is happening here. Why does CALayer not reflect the opacity value I set to it some time later after I added a CABasicAnimation for opacity? Is this a bug?

What am I doing wrong?

  • 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-11T09:28:19+00:00Added an answer on June 11, 2026 at 9:28 am

    You set the animation’s removedOnCompletion to NO. This means that when the animation completes, it still stays on the layer and still controls the value of opacity for the purposes of rendering. When you call this code a second time, the new animation replaces the old, which causes the jump (as it’s now using the newly-set 0.25f as the start point).

    The solution is to just stop setting removedOnCompletion to NO. Instead, you should just set the actual opacity of the layer to the same value as the endpoint of the animation., at the same time as you add the animation.

    CABasicAnimation *animation = [CABasicAnimation animationWithKeyPath:@"opacity"];
    // you can omit fromValue since you're setting it to the layer's opacity
    // by omitting fromValue, it uses the current value instead. Just remember
    // to not change layer.opacity until after you add the animation to the layer
    animation.toValue = [NSNumber numberWithFloat:1];
    animation.duration = 0.5;
    animation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseOut];
    [layer addAnimation:animation forKey:@"opacity"];
    layer.opacity = 1; // or layer.opacity = [animation.toValue floatValue];
    

    The reason for this is because of the way layer rendering works. When CoreAnimation renders a layer tree to the screen, it copies the model tree and produces what’s called the presentation tree. It does this by copying all the layers, and then applying all the animations. So it goes over each animation on the layer, plugs the time into the timing function, plugs the resulting progress into the interpolation between the from/to values, and applies that final value back onto the presentation layer’s property.

    So when you leave an animation on the layer permanently, this animation will always override whatever the actual model value is for the key. It doesn’t matter how many times you change layer.opacity, the animation that controls opacity will always overwrite the value for presentation purposes.

    This same reason is also why you can set the layer.opacity to whatever you want after adding the animation, because the animation will take precedence. Only when the animation is removed (which happens by default when the animation completes) will the model value for that property get used again.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a view model coming from the server as json like this {
i have view which looks something like this : <% using (Ajax.BeginForm(new AjaxOptions {
I can't update the view model. I have view called: Overview I have this
In My Application i have View like this image: Now, I want to make
I have a layer-hosting view set up like this in a custom NSView subclass:
i have view like 'home/details/5', it can be access by anonymous user. but there
I have view stack in a app like so: <mx:ViewStack id=viewStack left=0 right=0 top=0
Here there, I have a custom UIView. This view acts as a activity indicator
I have a CALayer and as sublayer to this CALayer i have added an
I have View with MKMapView: - (void)viewDidLoad { [super viewDidLoad]; self.navigationController.toolbarHidden = NO; /*

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.