Skip navigation.
 
mlCALayer/CAAnimation doesn't animate
FROM : Joachim
DATE : Mon Jan 14 23:37:10 2008

I have spent hours on this - I now throw in the towel...

I have a view that will contain several layers I want to animate. 
There are no subviews in my view, and I'd like to keep it that way.

I have made this simple example to illustrate the problem. It's a 
method of the view that is supposed to add a layer and animate it:

- (void)animateNewLayer
{
    // Create layer
    CALayer *layer = [CALayer layer];

    // Configure layer
    layer.frame = CGRectMake (0, 0, 24, 24);
    layer.contents = myCGImageRef; // Created earlier in this method
    CGImageRelease (myCGImageRef);

    // Add the layer to our view's root layer
    self.wantsLayer = YES;
    [self.layer addSublayer:layer];

    // Create animation
    CABasicAnimation *anim = [CABasicAnimation 
animationWithKeyPath:@"frameOrigin"];

    // Configure animation
    anim.fromValue      = [NSValue valueWithPoint:NSMakePoint (0, 0)];
    anim.toValue        = [NSValue valueWithPoint:NSMakePoint (100, 
100)];
    anim.timingFunction = [CAMediaTimingFunction 
functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
    anim.duration      = 2.0;
    anim.delegate      = self;

    // Add animation to layer; also triggers the animation
    [layer addAnimation:anim forKey:@"frameOrigin"];
}

There are several problems with this code:

1) When the code runs, the layer appears containing the loaded image 
at (0, 0) as expected, but it doesn't move
2) If I change the keyPath to either @"opacity" or @"borderWidth", the 
layer does animate, but as soon as it's done animating, the layer goes 
back to its original appearance, and the animation doesn't take the 2 
secs to complete - only a fraction
3) The delegate method, animationDidStart:, is only called in (2), not 
in (1), and animationDidStop: is never called in any of the scenarios

I'm totally stuck in this. Any help is hugely appreciated. I think I'm 
doing what's suggested in the examples in Core Animation Programming 
Guide, but obviously not.

Am I handling the layer hierarchy correctly? For example, can I use 
the view's backing layer as the root of the layer hierarchy?

Thaks in advance,
Joachim

Related mailsAuthorDate
mlCALayer/CAAnimation doesn't animate Joachim Jan 14, 23:37
mlRe: CALayer/CAAnimation doesn't animate Bill Dudney Jan 15, 00:07
mlRe: CALayer/CAAnimation doesn't animate Scott Anguish Jan 15, 09:10
mlRe: CALayer/CAAnimation doesn't animate Joachim Jan 15, 15:38
mlRe: CALayer/CAAnimation doesn't animate Bill Dudney Jan 15, 21:54
mlRe: [SOLVED] CALayer/CAAnimation doesn't animate Joachim Jan 16, 10:31