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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T17:09:04+00:00 2026-05-28T17:09:04+00:00

I have a subclass of CALayer with a custom property, declared as such: @interface

  • 0

I have a subclass of CALayer with a custom property, declared as such:

@interface MyLayer : CALayer
    @property (nonatomic,retain) NSNumber *customValue;
@end
@implementation MyLayer
    @synthesize customValue = _customValue;
@end

I want to animate this property inside of an explicit CATranasction, so i set up a delegate with the actionForLayer:forKey: method implemented which returns an animation, however any changes to someMyLayerInstance.customValue inside of [CATransaction begin] ... [CATransaction end] do not result in actionForLayer:forKey getting called with a corresponding ‘key’ value.

However, nuking the property on MyLayer and making changes to myLayerInstance by calling setValue:forKey: does result in actionForLayer:forKey: getting called.

It appears that this is because CALayer does some mojo for key/value coding for undefined properties. How can I recreate this mojo so that I can declare properties on MyLayer, but still have them be observed by the animation delegate?

  • 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-28T17:09:05+00:00Added an answer on May 28, 2026 at 5:09 pm

    The most important thing is that you need to implement all CALayer accessors using @dynamic. Do not use @synthesize and do not implement the accessors directly. CALayer generates all its own property handlers (as you’ve indirectly discovered), and you need to let those be used.

    You also need to let CALayer know that this property is display-impacting (which you may have already done given your other comments). If you haven’t, you do this by implementing +needsDisplayForKey: and returning YES for your key.

    Here’s an example of a CALayer that animates a custom property (taken from Chapter 7 of iOS 5 Programming Pushing the Limits. The full sample code is available at the Wiley site.) This example implements actionForKey: in the layer, but you can still implement that part in the delegate if you prefer.

    @implementation CircleLayer
    @dynamic radius;
    
    ...
    
    + (BOOL)needsDisplayForKey:(NSString *)key {
      if ([key isEqualToString:@"radius"]) {
        return YES;
      }
      return [super needsDisplayForKey:key];
    }
    
    - (id < CAAction >)actionForKey:(NSString *)key {
      if ([self presentationLayer] != nil) {
        if ([key isEqualToString:@"radius"]) {
          CABasicAnimation *anim = [CABasicAnimation
                                    animationWithKeyPath:@"radius"];
          anim.fromValue = [[self presentationLayer] 
                            valueForKey:@"radius"];
          return anim;
        }
      }
    
      return [super actionForKey:key];
    }
    
    @end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a very simple subclass of UIButton: @interface MyButton : UIButton @end @implementation
I have a custom UIView subclass that i'm trying to use as a header
I have a CABasicAnimation that animating a property of a CALayer e.g. bounds.origin .
There is Class A with: @interface ClassA : NSObject { } @property (nonatomic, assign)
I have a simple CALayer subclass (BoxLayer) with this drawLayer method: - (void)drawLayer:(CALayer *)layer
I have a CALayer subclass that is constrained to the width of the parent
I have a UIViewController where I am adding a CALayer subclass to the view's
I have a subclass of UIViewController with an NSMutableArray as a property to use
I have a subclass defined as follows, #import <Cocoa/Cocoa.h> @interface ICMusicBrowserWindowController : NSWindowController {
I have a layer-hosting view set up like this in a custom NSView subclass:

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.