我有一个CALayer
子类,其中 floatanimAngle
作为属性标记为@dynamic
. 我已经实现了方法actionForKey
、、initWithLayer
和needsDisplayForKey
子drawInContext
类。的定义actionForKey
如下
- (id<CAAction>)actionForKey:(NString *)event {
if([event isEqualToString:@"animAngle"]) {
return [self animationForKey:event];
}
return [super actionForKey:event];
}
和
- (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;
}
在其他类:
myCASublayer.animAngle = 0.5f;
不知何故,CABasicAnimation
被返回的东西无法正确使用图层“ animAngle
”属性。我在这里可能做错了什么?