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

  • Home
  • SEARCH
  • 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 973523
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T03:17:32+00:00 2026-05-16T03:17:32+00:00

I’ve been trying to understand what is wrong with my animation and I still

  • 0

I’ve been trying to understand what is wrong with my animation and I still haven’t figure it out. I think it should be really straight forward, but there is probably something I’m missing, even after reading lot of examples and documentation.

My problem comes originally form the fact that on the iPhone, you cannot resize layers automatically (with the view). The documentation says otherwise but there is no autoresizeMask for the layer in the SDKs. So I decided to make a little workaround and animate the layer myself.

I’ve got this simple piece of code that should do a simple resize animation. The values are good and I even set the delegate in order to trace if the anim start/end.

// I've got a property named layerImage (which is a CALayer)
- (void)animateTestWithFrame:(CGRect)value {
    CABasicAnimation *animation = [CABasicAnimation animationWithKeyPath:@"layerImage.frame"];
    animation.duration = 1;
    animation.fromValue = [NSValue valueWithCGRect:self.frame];
    animation.toValue = [NSValue valueWithCGRect:value];
    animation.removedOnCompletion = YES;
    animation.delegate = self;

    [self.layer addAnimation:animation forKey:@"layerImage.frame"];
}

So, any ideas? (This view that contains the code is the subview of a subview of the window if that could make a difference)

— EDIT —

It seems that frame is not animatable via CABasicAnimation and the named property “frame”. When using bounds, I’ve got some strange result, but at least I’m getting something. Will continue investigating on this.

  • 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-16T03:17:32+00:00Added an answer on May 16, 2026 at 3:17 am

    So it’s good that you’ve figured things out here, but your answer to your own question has some inaccuracies. Let me correct a few things:

    The frame property can be animated–just not with explicit animation. If you do the following to a layer other than the root layer of a view, the frame will animate just fine:

    [CATransaction begin];
    [CATransaction setAnimationDuration:2.0f];
    [animationLayer setFrame:CGRectMake(100.0f, 100.0f, 100.0f, 100.0f)];
    [CATransaction commit];
    

    Remember that setting a property on a layer will animate that property change by default. In fact you have to disable animations on a property change if you don’t want it to animate. (Of course this is only true if you are animating a layer other than the root layer of a view.) You are correct in animating both position and bounds if you need to use an explicit animation.

    You can animate the frame on a UIView using implicit animation:

    [UIView beginAnimations:nil context:NULL];
    [UIView setAnimationDuration:3.0f];
    [[self view] setFrame:CGRectMake(45.0f, 45.0f, 100.0f, 100.0f)];
    [UIView commitAnimations];
    

    This will animate from the view’s current frame (bounds and position) to x = 45.0, y = 45.0, w = 100.0, h = 100.0.

    It seems you may also be misunderstanding the difference between an animation and a layer. You add animations to layers, but adding an animation to a layer does not automatically set the property that you’re animating.

    CALayers are model objects. They contain information about the layer that eventually gets rendered to screen. You must set a layer’s property if you want that property to actually have that value. If you simply animate the property, it will only be a visual representation and not actual–which is to say this is why the value snaps back to the original value of the layer because you never actually changed it.

    Which leads me to the next point. You said:

    Use “animation.removedOnCompletion =
    NO; animation.fillMode =
    kCAFillModeForwards;” to ensure that
    the values are not reseted at the end
    of the animation

    This is not exactly right. These two values simply cause the animation to remain at it’s final position visually, however, the layer’s actual values have not changed. They are still the exact same values they were when you started the animation. In general (with a few exceptions) you don’t want to use these two parameters because they are visual only. What you want is to actually set the layer value for the property you’re animating.

    Say, for example, that you want to animate the position of your layer using an explicit animation. Here is the code you want:

    CABasicAnimation *animation = [CABasicAnimation animationWithKeyPath:@"position"];
    [animation setFromValue:[NSValue valueWithCGPoint:CGPointMake(70.0f, 70.0f)]];
    [animation setToValue:[NSValue valueWithCGPoint:CGPointMake(150.0f, 150.0f)]];
    [animation setDuration:2.0f];
    
    // Actually set the position on the *layer* that you want it to be
    // when the animation finishes.
    [animationLayer setPosition:CGPointMake(150.0f, 150.0f)];
    
    // Add the animation for the position key to ensure that you
    // override the animation for position changes with your animation.
    [animationLayer addAnimation:animation forKey:@"position"];
    

    You may also want to consider animation grouping. With an animation group, you can group several animations together and then control how they relate to each other. In your case the duration for your bounds and position animations are the same and so what you are trying to do will work fine without a group, but if you wanted to offset the start of the animations, for example you didn’t want the position animation to start until a second or two into the frame animation, you could stagger them by setting the beginTime value of the position animation.

    Finally, I would be curious to know why you couldn’t use the implicit animations available on UIView. I use these in the vast majority of the Core Animation code I write and can’t see why this wouldn’t work for your situation.

    Best regards.

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

Sidebar

Related Questions

I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I am trying to understand how to use SyndicationItem to display feed which is
I have a jquery bug and I've been looking for hours now, I can't
link Im having trouble converting the html entites into html characters, (&# 8217;) i
Basically, what I'm trying to create is a page of div tags, each has
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I am trying to render a haml file in a javascript response like so:
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I'm trying to use string.replace('’','') to replace the dreaded weird single-quote character: ’ (aka
I'm trying to create an if statement in PHP that prevents a single post

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.