2012-01-01 12 views
1

以下は私が使用するコードです。アニメーションは機能します。しかし、それはそれの後の元の状態に戻った。私のコードに何か問題はありますか?ありがとう。iphone - アニメーションが元の状態に戻る

-(void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event{ 
    CABasicAnimation *expand=[CABasicAnimation animationWithKeyPath:@"transform"]; 
    expand.toValue=[NSValue valueWithCATransform3D:CATransform3DMakeScale(1.2, 1.2, 1.0)]; 
    expand.autoreverses=NO; 
    expand.removedOnCompletion=YES; 

    CABasicAnimation *opacityAnimation = [CABasicAnimation animationWithKeyPath:@"opacity"]; 
    opacityAnimation.toValue = [NSNumber numberWithFloat:0.0f]; 
    opacityAnimation.autoreverses=NO; 
    opacityAnimation.removedOnCompletion=YES; 

    CAAnimationGroup *group=[CAAnimationGroup animation]; 
    group.animations=[[NSArray alloc] initWithObjects:expand,opacityAnimation, nil]; 
    group.duration=1.0; 
    group.fillMode=kCAFillModeForwards; 
    group.timingFunction=[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseOut]; 
    [view1.layer addAnimation:group forKey:@"expand"]; 

} 

答えて

1

あなたはremovedOnCompletion完了後にアニメーションを削除することを指定したYESに設定されています。代わりにNOを試してください。

+0

まだ動作しません –

0

ジャンプバックを取り除くための簡単な方法は、明示的に有効に行動せずにCATransactionを使用してあなたがアニメーション化された値を持つモデル層を更新することです:

[CATransaction begin]; 
[CATransaction setDisableActions:YES]; 

//this will update the model layer 
view1.layer.transform = CATransform3DMakeScale(1.2, 1.2, 1.0); 
view1.layer.opacity = 0.f; 

//your basic animations will animate the presentation layer 
/* your CABasicAnimations here */ 

[CATransaction commit]; 

はないセットを行いますremovedOnCompletionこれにより、アニメーションが永久に続き、モデルレイヤーがプレゼンテーションレイヤーが表示している位置で更新されることはないため、ビューを保持するためにNOに移動します。また、実際に動いていないビューをアニメーション化しているので、アニメーションを削除しないことでパフォーマンスの低下を招くこともあります。

0
CAAnimationGroup *group=[CAAnimationGroup animation]; 
group.animations=[[NSArray alloc] initWithObjects:expand,opacityAnimation, nil]; 
group.duration=1.0; 
group.removedOnCompletion=NO; 
group.fillMode=kCAFillModeForwards; 
group.timingFunction=[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseOut]; 
[view1.layer addAnimation:group forKey:@"expand"]; 

それはあなたのために働くことがあり、グループアニメーションでNOとして removedOnCompletionてみてください。

関連する問題