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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T08:31:01+00:00 2026-05-12T08:31:01+00:00

Core Animation allows for custom animations by implementing the actionForKey method in your CALayer

  • 0

Core Animation allows for custom animations by implementing the actionForKey method in your CALayer based class:

- (id<CAAction>)actionForKey:(NSString *)key {
    // Custom animations
    return [super actionForKey:key];
}

I can then create an animation and return it for the onOrderIn action (i.e. when the layer is added to another layer). This works just fine. If I do the same for onOrderOut (i.e. the layer is removed from its superlayer), the returned animation is ignored, and the default animation is applied instead.

My goal is to zoom the layer in (onOrderIn) and out (onOrderOut):

- (id<CAAction>)actionForKey:(NSString *)key {

    if ([key isEqualToString:@"onOrderIn"] || [key isEqualToString:@"onOrderOut"]) {
        CABasicAnimation *a = [CABasicAnimation animationWithKeyPath:@"transform.scale"];
        a.duration = 0.25;
        a.removedOnCompletion = NO;
        a.fillMode = kCAFillModeBoth;

        if ([key isEqualToString:@"onOrderIn"]) {
            a.fromValue = [NSNumber numberWithFloat:0.0];
            a.toValue = [NSNumber numberWithFloat:1.0];
        } else {
            a.fromValue = [NSNumber numberWithFloat:1.0];
            a.toValue = [NSNumber numberWithFloat:0.0];
        }

        return a;
    }

    return [super actionForKey:key];
}

Zooming in works, zooming out does not. Instead the default fade out animation is used.

The code might contain some typos, as I’m typing this on another machine.

Can anyone help?

  • 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-12T08:31:01+00:00Added an answer on May 12, 2026 at 8:31 am

    Quoting John Harper on quartz-dev mailing list:

    There’s a fundamental problem with
    returning any animation for the
    onOrderOut key—by the time the
    animation should be running, the layer
    is no longer in the tree, so it has no
    effect. So onOrderOut is not useful
    for triggering animations; it may be
    useful for running other code when
    layers are removed from the tree.

    The best solution I’ve found for this
    (assuming the default fade transition
    on the parent is not what you want,
    which it often isn’t) is to add custom
    animations to apply the removal effect
    you want, then, in the didStop
    animation delegate, actually remove
    the layer. It’s often convenient to
    create a single group of animations
    with the delegate property set, and
    fillMode=forwards,
    removedOnCompletion=NO so that you can
    remove the layer at the end of the
    animation with no possibility of the
    layer still being visible in its
    normal state.

    If you do many case of this, it is easy to write a common superclass that starts an animation, sets the animation delegate to the class and implements +animationDidStop: to remove the layer w/o animation enabled. This restores the fire-and-forget nature of CoreAnimation that you’d have hoped would be present with the default implementation.

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

Sidebar

Ask A Question

Stats

  • Questions 182k
  • Answers 182k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer It is possible, but you'll have to do it after… May 12, 2026 at 4:22 pm
  • Editorial Team
    Editorial Team added an answer Take a look at my answer here - JQuery datepicker-… May 12, 2026 at 4:22 pm
  • Editorial Team
    Editorial Team added an answer If you use XSLT, its possible to call a custom-supplied… May 12, 2026 at 4:22 pm

Related Questions

I would like to create a custom NSView that takes a layered approach to
Please pardon my lack of Photoshop skills, but I'm curious what type of strategy
I'm currently using a UIImageView with an array of images to create a small
If I'm looking to use Core Animation to fade a view in and out

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.