CALayer/CAAnimation doesn't animate
CALayer/CAAnimation doesn't animate
- Subject: CALayer/CAAnimation doesn't animate
- From: Joachim <email@hidden>
- Date: Mon, 14 Jan 2008 23:37:10 +0100
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
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden