I have a CALayer
subclass with float animAngle
as property marked as @dynamic
. I have implemented methods actionForKey
, initWithLayer
, needsDisplayForKey
and drawInContext
for subclass. The definition for actionForKey
is as follows
- (id<CAAction>)actionForKey:(NString *)event {
if([event isEqualToString:@"animAngle"]) {
return [self animationForKey:event];
}
return [super actionForKey:event];
}
And
- (CABasicAnimation *)animationForKey:(NSString *)key
{
NSString *animValue = [[self presentationLayer] valueForKey:key];// Logs as 0
CABasicAnimation *anim;
if([key isEqualToString:@"animAngle"]) {
anim = [CABasicAnimation animationWithKeyPath:@"transform.rotation.z"];
anim.repeatCount = HUGE_VAL;
anim.autoreverses = YES;
//anim.fromValue = [[self presentationLayer] valueForKey:key]; // setting animation value from layer property as in here does not work.
anim.fromValue = [NSNumber numberWithFloat:0.5f]; // This works
}
anim.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
anim.duration = 0.11;
return anim;
}
In Someother class:
myCASublayer.animAngle = 0.5f;
Somehow the CABasicAnimation
being returned is not able to properly use the layer " animAngle
" property. What would i be possibly doing wrong here?
If animAngle
is a @property
- you must specify accessors
for this property.
When you mark property as @dynamic
this means, that you will provide an implementation of those methods dynamically at runtime. So, if you do not provide accessors for property, you can't access it.
CocoaHeads Session: Rob Napier on Animating Custom Layer Properties is a good presentation about custom animations.
CALayers hate do draw ;)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.