Re: Custom CALayer Action as animation key?
Re: Custom CALayer Action as animation key?
- Subject: Re: Custom CALayer Action as animation key?
- From: Matt Long <email@hidden>
- Date: Mon, 20 Oct 2008 21:04:13 -0600
Patrick,
I believe the only animatable properties are the ones explicitly
labeled "animatable" in the documentation. That is why (I believe)
there is a section labeled "Animatable Properties" in the Core
Animation Programming guide. I think the reason is that you can't
guarantee that your custom property is something that can be
interpolated.
The only way that you can trigger an action for a custom key is to
explicitly change the value for that key--which is why your call to
[content setValue:[NSNumber numberWithInt:19] forKey:@"test"]; works.
It is also why it worked when you specified bounds.size.width as this
is an actual animatable property.
Hope that helps.
-Matt
On Oct 20, 2008, at 9:58 AM, Patrick Mau wrote:
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