Dany Joumaa
Dany Joumaa

Reputation: 2040

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?

Upvotes: 2

Views: 987

Answers (1)

rob mayoff
rob mayoff

Reputation: 385500

Replace your addSublayer: call with this:

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

Upvotes: 3

Related Questions