サブクラスのfloatがanimAngle
の場合、@dynamic
とマークされています。私はサブクラスにメソッドactionForKey
、initWithLayer
、needsDisplayForKey
とdrawInContext
を実装しました。どういうわけかCABasicAnimation
が返されるCALayerサブクラスがプロパティの変更にアニメートしない
myCASublayer.animAngle = 0.5f;
が適切層 "animAngle
" を使用することができません。
- (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;
}
を次のように actionForKey
の定義がありますプロパティ。 私はおそらくここで間違っているでしょうか?
一つは 'animAngle'他は' wiggleAngle' –
@RobvanderVeerであると呼ばれています。そのanimAngle。 – rawatm
@ basstrekerk87、次回コピー/貼り付けがうまくいくと、エラーを保存します!実際に手動でコードをインデントする必要はありません。ボタンを使用するか、3つのバッククォート( ')で開始してください。 –