Custom CAGradientLayer doesn't animate
I've made a custom class of CAGradientLayer (added radial gradient option).
I works but I can't figure out why I can't animate the colors.

Here's my code.

The animation is a simple CABasicAnimation where I set the toValue to a new array with colors.

    #import "ExtCAGradientLayer.h"
        
    NSString * const kExt_CAGradientLayerRadial = @"RadialGradient";
        
    @implementation ExtCAGradientLayer
    @synthesize gradientDrawingOptions;
        
    +(BOOL)needsDisplayForKey:(NSString *)key
    {
       return [key isEqualToString:@"type"] || [super needsDisplayForKey:key];
    }
        
    - (void)drawInContext:(CGContextRef)theContext
    {
       if ([self.type isEqualToString:kExt_CAGradientLayerRadial]) {
        size_t num_locations = self.locations.count;
        
        int numbOfComponents = 0;
        CGColorSpaceRef colorSpace = NULL;
        
        if (self.colors.count) {
            CGColorRef colorRef = (__bridge CGColorRef)[self.colors objectAtIndex:0];
            numbOfComponents = CGColorGetNumberOfComponents(colorRef);
            colorSpace = CGColorGetColorSpace(colorRef);
        }
        
        float *locations = calloc(num_locations, sizeof(float));
        float *components = calloc(num_locations, numbOfComponents * sizeof(float));
        
        for (int x = 0; x < num_locations; x++) {
            locations[x] = [[self.locations objectAtIndex:x] floatValue];
            const CGFloat *comps = CGColorGetComponents((__bridge CGColorRef)[self.colors objectAtIndex:x]);
            for (int y = 0; y < numbOfComponents; y++) {
                int shift = numbOfComponents * x;
                components[shift + y] = comps[y];
            }
        }
        
        CGPoint position = CGPointMake(CGRectGetMidX(self.bounds), CGRectGetMidY(self.bounds));
        CGFloat radius = floorf(MIN(self.bounds.size.width, self.bounds.size.height) / 2);
        CGGradientRef gradient = CGGradientCreateWithColorComponents(colorSpace, components, locations, num_locations);

        CGContextDrawRadialGradient(theContext, gradient, position, 0, position, radius, self.gradientDrawingOptions);
        
        free(locations);
        free(components);
    }
Custom CAGradientLayer doesn't animate
===

I've made a custom class of CAGradientLayer (added radial gradient option).
I works but I can't figure out why I can't animate the colors.

Here's my code.

The animation is a simple CABasicAnimation where I set the toValue to a new array with colors.

    #import "ExtCAGradientLayer.h"
        
    NSString * const kExt_CAGradientLayerRadial = @"RadialGradient";
        
    @implementation ExtCAGradientLayer
    @synthesize gradientDrawingOptions;
        
    +(BOOL)needsDisplayForKey:(NSString *)key
    {
       return [key isEqualToString:@"type"] || [super needsDisplayForKey:key];
    }
        
    - (void)drawInContext:(CGContextRef)theContext
    {
       if ([self.type isEqualToString:kExt_CAGradientLayerRadial]) {
        size_t num_locations = self.locations.count;
        
        int numbOfComponents = 0;
        CGColorSpaceRef colorSpace = NULL;
        
        if (self.colors.count) {
            CGColorRef colorRef = (__bridge CGColorRef)[self.colors objectAtIndex:0];
            numbOfComponents = CGColorGetNumberOfComponents(colorRef);
            colorSpace = CGColorGetColorSpace(colorRef);
        }
        
        float *locations = calloc(num_locations, sizeof(float));
        float *components = calloc(num_locations, numbOfComponents * sizeof(float));
        
        for (int x = 0; x < num_locations; x++) {
            locations[x] = [[self.locations objectAtIndex:x] floatValue];
            const CGFloat *comps = CGColorGetComponents((__bridge CGColorRef)[self.colors objectAtIndex:x]);
            for (int y = 0; y < numbOfComponents; y++) {
                int shift = numbOfComponents * x;
                components[shift + y] = comps[y];
            }
        }
        
        CGPoint position = CGPointMake(CGRectGetMidX(self.bounds), CGRectGetMidY(self.bounds));
        CGFloat radius = floorf(MIN(self.bounds.size.width, self.bounds.size.height) / 2);
        CGGradientRef gradient = CGGradientCreateWithColorComponents(colorSpace, components, locations, num_locations);

        CGContextDrawRadialGradient(theContext, gradient, position, 0, position, radius, self.gradientDrawingOptions);
        
        free(locations);
        free(components);
    }