我有一个CALayer
子类,带有浮点数属性animAngle
,标记为@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
" 属性。我可能做错了什么?
animAngle
,另一个被称为wiggleAngle
。 - Rob van der Veer