Search code examples
ioscore-animation

Implicit animation fade-in is not working


I have a UIView subclass which seeks to create a rounded rect overlay on top of one of its subviews.

When I use the code below, surely enough, a green rounded rect appears where I want it, but no matter what I do, I can't get it to fade in.

CALayer *parentLayer = [self layer];

// Create a new layer and configure it to be a rounded rect box overlay
CALayer *layer = [CALayer layer];
layer.position = [slider layer].position;
layer.bounds = CGRectMake(0.0, 0.0, kWTFSliderWidth, kWTFSliderHeight);
layer.backgroundColor = [UIColor clearColor].CGColor;
layer.cornerRadius = 5.0;
layer.borderColor = [UIColor greenColor].CGColor;
layer.borderWidth = 3.0;

// Add the layer with a fade in to the parent layer
[parentLayer addSublayer:layer];

Do I have to add CABasicAnimation manually to my parent layer object? Shouldn't a default instance already be present in parentLayer's action dictionary?


Solution

  • Replace your addSublayer: call with this:

    layer.hidden = YES;
    [parentLayer addSublayer:layer];
    [CATransaction flush];
    layer.hidden = NO;