Custom CALayer Action as animation key?
Custom CALayer Action as animation key?
- Subject: Custom CALayer Action as animation key?
- From: Patrick Mau <email@hidden>
- Date: Mon, 20 Oct 2008 17:58:51 +0200
Good afternoon,
I have implemented a layer-based view that acts as the layer delegate
and defines a layer action named "test".
Afterwards I create a CABasic animation to animate the test property.
If you look at the line marked 'THIS WORKS",
you'll see that sending "setValue:forKey" triggers a message
"runActionForKey:object:arguments",
but using the property for a basic animation will not trigger the
CAAction.
So here's my simple question. What is needed to "animate" a generic
property named test?
Did I mis-read the documentation and wrongly assumed that any property
can be used as
long as there's a CAAction?
By the way, changing the "keyPath" to something like
"bounds.size.width" works as expected.
The small zip is at:
http://oscar.homelinux.net/layer.zip
Please don't mind the coding style.
Thanks a lot,
Patrick
--- Small excerpt ---
/* Debug invocation of CAAction */
- (void) runActionForKey:(NSString *)key object:(id)object arguments:
(NSDictionary *)dict
{
NSLog(@"runActionForKey:\"%@\" object:%p arguments:%p", key,
object, dict);
}
/* Get the CAAction for "test", or nil for all others */
- (id<CAAction>) actionForLayer:(CALayer *)theLayer forKey:(NSString
*)theKey
{
id res = [theLayer.actions valueForKey:theKey];
NSLog(@"actionForLayer:%p forKey:\"%@\" = %p", theLayer, theKey,
res);
return res;
}
/* Create the layer, initialize action, animate "test" property */
- (void) createLayer {
// ...
content = [CALayer layer];
content.actions = [NSDictionary
dictionaryWithObjectsAndKeys:self, @"test", nil];
// ...
[content setDelegate:self];
[content setNeedsDisplay];
// THIS WORKS!
[content setValue:[NSNumber numberWithInt:19] forKey:@"test"];
// THIS does not work.
CABasicAnimation *anim = [CABasicAnimation animation];
anim.keyPath = @"self.test";
anim.duration = 1.0;
anim.repeatCount = 1.0e100;
anim.autoreverses = YES;
anim.fromValue = [NSNumber numberWithFloat:0.0];
anim.toValue = [NSNumber numberWithFloat:1.0];
[content addAnimation:anim forKey:@"test"];
}
_______________________________________________
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