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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T04:33:44+00:00 2026-05-21T04:33:44+00:00

I have a CALayer subclass that is constrained to the width of the parent

  • 0

I have a CALayer subclass that is constrained to the width of the parent layer, but a fixed height. I want the implicit animation disabled for resizing the window but enabled whenever I set the height of the layer.

To disable the animation when the window is resized I set the layers actions to

NSMutableDictionary *actions = [[NSMutableDictionary alloc] initWithObjectsAndKeys:[NSNull null], @"bounds", [NSNull null], @"position", nil];

and this seems to work. Then I’ve overridden the actionForKey: method in my layer subclass

- (id<CAAction>)actionForKey:(NSString *)event
{
    if ([event isEqualToString:@"frame.size.height"]) {
        CABasicAnimation *animation = [CABasicAnimation animationWithKeyPath:@"frame.size.height"];
        [animation setDuration:0.5f];
        return animation;
    }
    return nil;
}

but then when I change the height of my layer with

[layer setValue:[NSNumber numberForFloat:50.0] forKey:@"frame.size.height"];

the height changes but is not animated. I see the actionForKey: method being called with frame.size.height but no matter what I return it is never animated. The height animates correctly if I don’t set the actions, or have the actionForKey: method, but then the window resizes are also animated, which I don’t want.

Also, maybe I’m misunderstanding, but I thought returning nil from actionForKey: would make the default animations run, but it appears that even the presence of the method stops all implicit animations (whether the actions dictionary is set or not).

What is it am I missing here, I’ll be grateful for any pointers.

  • 1 1 Answer
  • 1 View
  • 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-21T04:33:45+00:00Added an answer on May 21, 2026 at 4:33 am

    Your subclass is going to get actionForKey: called on it for every key, so if you return nil, there won’t be an action for that key. If you want the default animations, you should return either [super actionForKey:event] or [CALayer defaultActionForKey:event].

    A layer’s frame is calculated from its bounds and position, so if there’s no animation for those two, there can’t be an animation for frame.*

    What you want to do is:

    [CATransaction setValue:kCFBooleanTrue
                     forKey:kCATransactionDisableActions]
    

    when your layer resizes as a result of the window resizing. This will disable animation just this time (for this transaction); when you change the layer’s size directly, it will still animate. I’m not sure what the correct spot to do that call is; I just tried doing it in a callback from notification that the window was resizing, but that didn’t work. I’m sure it won’t be too hard for you to figure out where to put it in your code.


    *: In fact, the docs say:

    Note: The frame property is not directly animatable. Instead you should animate the appropriate combination of the bounds, anchorPoint and position properties to achieve the desired result.

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

Sidebar

Related Questions

I have a CALayer that I want to animate across the screen. I have
I have a simple CALayer subclass (BoxLayer) with this drawLayer method: - (void)drawLayer:(CALayer *)layer
For example I have this CAKeyFrameAnimation: CALayer* theLayer = myView.layer; CAKeyframeAnimation* animation; animation =
I have a UIView & I want that view's layer to be a continuously
I have created a CALayer (I added several shapes to the layer, but ultimately,
So, I have a CALayer added to a UIScrollView that does some path animations.
I have one like this: CALayer *layer = stripeButton.layer; CAKeyframeAnimation *moveAnim = [CAKeyframeAnimation animationWithKeyPath:@bounds.origin.y];
I have a UIView that contains a number of CALayer subclasses. I am using
I have a CALayer that I apply a perspective to using a CGTransform3D and
I have a UIView class that I am using to have a CALayer. This

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.