CALayer子类不动画属性更改

Mad*_*wat 6 calayer caanimation ios

我有一个CALayer子类,其float animAngle属性标记为@dynamic.我已经实现的方法actionForKey,initWithLayer,needsDisplayForKeydrawInContext为子类.定义actionForKey如下

- (id<CAAction>)actionForKey:(NString *)event {
    if([event isEqualToString:@"animAngle"]) {
        return [self animationForKey:event];
    }
    return [super actionForKey:event];
}
Run Code Online (Sandbox Code Playgroud)

- (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;
}
Run Code Online (Sandbox Code Playgroud)

在其他类:

myCASublayer.animAngle = 0.5f;
Run Code Online (Sandbox Code Playgroud)

以某种方式CABasicAnimation返回的是无法正确使用图层" animAngle"属性.我在这里可能做错了什么?

Dav*_*ist 1

CocoaHeads Session:Rob Napier on Animating Custom Layer Properties是关于自定义动画的一个很好的演示。

CALayers 讨厌画画;)