0

意図: ボタン クリックは、別のボタン クリック リクエストによって停止されるまで、CATextLayer オブジェクトの文字列値をアニメーション化することをリクエストします。アクションが混乱しないように、これらのアクションを担当する 2 つの別個のボタンがあります。

実際に何が起こるか: 再生リクエストでは、textLayer の文字列がアニメーション化されず、その文字列値が変更されずに、割り当てられた「0」が表示される場合がいくつかあります (上記を参照)。この場合、アニメーションは初期化されず、CATextLayer オブジェクトに割り当てられません。ただし、エラーは一貫していません。CATextLayer オブジェクトが適切な文字列値を表示する場合もいくつかあります。ボタンを連続してクリックした場合、CATextLayer オブジェクトがその文字列値をアニメートするのを確認する成功率は約 70% です。addAnimation メソッドのコード行をバイパスするシナリオはありますか?

問題に関するご協力に感謝いたします。前もって感謝します!

-(IBAction)playText:(id)sender{
    //textLayer object is instantiated elsewhere in the class
    textLayer.frame = CGRectMake(0, 0, 128, 16);
    textLayer.fontSize = 14;
    textLayer.backgroundColor = [UIColor clearColor].CGColor;
    textLayer.foregroundColor = [UIColor yellowColor].CGColor;
    textLayer.string = @"0";
    [self.layer addSubLayer:textLayer];

    CAKeyframeAnimation *textAnimation = [CAKeyframeAnimation animationWithKeyPath:@"string"];
    textAnimation.values = values; 
    textAnimation.repeatCount = HUGE_VALF;
    textAnimation.keyTimes = intervals; 
    textAnimation.calculationMode = kCAAnimationLinear;
    textAnimation.duration = 6;
    [textLayer addAnimation:textAnimation forKey:@"string"];
}

-(IBAction)stopText:(id)sender{
    [textLayer removeAnimationForKey:@"string"];
}
4

1 に答える 1

1

オブジェクトは、その親サブレイヤーに再追加するだけでなく、キーフレーム アニメーションごとに再初期化する必要があります。

于 2012-01-12T20:06:01.960 に答える