ブロックを使用するiOS5.0では、UIViewAnimationOptionAutoreverseアニメーションがあり、逆アニメーションが開始する前に遅延を入れる必要があるとします..どうすればこれを行うことができますか?
これについてのあなたの助けに感謝します
次のようなアニメーション完了ブロックを試すことができます。
[UIView animateWithDuration:0.6 animations:^(void)
{
self.label.bounds = CGRectMake(10, 10, 200, 200);
}completion:^(BOOL finished) {
[UIView animateWithDuration:0.6 animations:^(void)
{
self.label.bounds = CGRectMake(10, 10, 100, 100);
}completion:^(BOOL finished) {
}];
}];
そのためには、キーフレームアニメーションを使用する必要があります。反転して回転を行うためのコードは次のとおりです。
self.animations = [NSDictionary dictionaryWithObjects: [NSArray arrayWithObjects: [CAKeyframeAnimation animationWithKeyPath:@"transform.rotation.z"], [CAKeyframeAnimation animationWithKeyPath:@"transform.rotation.z"] , nil ] forKeys: [NSArray arrayWithObjects: THERE_ANIM_KEY, BACK_AGAIN_ANIM_KEY , nil ]]; CAKeyframeAnimation *kfAnim = [animations objectForKey: THERE_ANIM_KEY]; kfAnim.duration = 2; kfAnim.repeatCount = 1; kfAnim.values = [NSArray arrayWithObjects: [NSNumber numberWithFloat: 0.0 * M_PI], [NSNumber numberWithFloat: 1.0 * M_PI], [NSNumber numberWithFloat: 2.0 * M_PI], [NSNumber numberWithFloat: 2.0 * M_PI], //here is delay [NSNumber numberWithFloat: 1.0 * M_PI], [NSNumber numberWithFloat: 0.0 * M_PI], nil]; kfAnim.keyTimes = [NSArray arrayWithObjects: [NSNumber numberWithFloat: 0.0 ], [NSNumber numberWithFloat: 0.3 ], [NSNumber numberWithFloat: 0.5 ], //time of delaying in proportion of general animation duration [NSNumber numberWithFloat: 0.5 ], [NSNumber numberWithFloat: 0.8 ], [NSNumber numberWithFloat: 1.0 ], nil];
また、初期状態の記憶を使用して、元に戻すことができます
- (void)animationDidStop:(CAAnimation *)theAnimationfinished:(BOOL)flag
PerformSelector:withObject:afterDelay:を使用したアニメーションデリゲートメソッド。これははるかに単純で、遅延の設定が簡単です。
これがまさにあなたがやろうとしていることかどうかはわかりませんが、ビューを画面に移動し、1秒間一時停止してからビューを画面外に移動するために使用しているものは次のとおりです。
[UIView animateWithDuration:0.5 animations:^{
self.view.frame = viewFrameOnScreen;
self.view.alpha = 1.0;
} completion:^(BOOL finished){
[UIView animateWithDuration:0.5 delay:1 options:0 animations:^{
self.view.frame = viewFrameOffScreen;
self.view.alpha = 0.0f;
} completion:^(BOOL finished){}];
}];