1

私は UIViewグローを前後に2回作ろうとしています。以下のアニメーションは機能しますが、終了した直後に、元の状態ではなく、アニメーション化した状態になります。オートリバースを YES に設定したのに、元の状態に戻らないのはなぜですか?

[UIView beginAnimations:nil context:NULL];
[UIView setAnimationRepeatCount:2];
[UIView setAnimationRepeatAutoreverses:YES];
[UIView setAnimationDuration:0.3];
[UIView setAnimationBeginsFromCurrentState:YES];
textDetailView.layer.backgroundColor = [UIColor colorWithRed:0 green:1 blue:0 alpha:0.3].CGColor;
[UIView commitAnimations];
4

1 に答える 1

1

アニメーションは反転しますが、値は反転しません。アニメーションが完了すると、それ自体がビューから (実際にはビュー レイヤーから) 削除され、ビューには設定されたプロパティが表示されます。

完了ブロックまたは使用している古い UIView アニメーションのセレクターで値を設定し直すことができます。

または、値が変化しないアニメーションの場合は、Core Animation を使用することでメリットが得られます (これは値をハングさせません (アニメーションの後、ビューは元の状態に戻ります))。

機能させるには、QuartzCore.framework をインポートしてインクルードする必要がありますQuartzCore/QuartzCore.h

を次のように更新する必要がある場合もあります。

CABasicAnimation *myColorAnimation = [CABasicAnimation animationWithKeyPath:@"backgroundColor"];
[myColorAnimation setAutoreverses:YES];
[myColorAnimation setRepeatCount:2];
[myColorAnimation setDuration:0.3];
[myColorAnimation setToValue:(id)[myColor CGColor]];
// the default "from value" is the current value
[[textDetailView layer] addAnimation:myColorAnimation forKey:@"myColorKey"];
于 2012-06-18T08:17:32.477 に答える