6

としてマークされたプロパティとしてCALayerfloatを持つサブクラスがあります。メソッド、、およびサブクラスを実装しました。の定義は次のとおりです。animAngle@dynamicactionForKeyinitWithLayerneedsDisplayForKeydrawInContextactionForKey

- (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ここで何が間違っているのでしょうか?

4

2 に答える 2

1

animAngleが - の場合、このプロパティに@property指定する必要があります。これは、実行時にこれらのメソッドの実装を動的に提供することを意味します 。そのため、プロパティにアクセサーを提供しないと、アクセスできません。accessors
@dynamic

于 2013-08-17T19:20:11.660 に答える