2009-07-21 17 views
1

私はUIImageViewで動きや回転アニメーションを使って車の画像を持っています。 私は車にサブビューとして追加したUIImageViewにタイヤマーク画像を持っています。 これは、すべて同じ動きアニメーションと回転アニメーションが両方に適用されることを意味します。アニメーション画像のトレイルを保存する

私がしたいことは、タイヤのスキッドマークのトレイルを残すことです。

誰でもこれを行う方法に関する戦略を提案できますか?

私はそれを使用できるかどうか確認してください、私はこのスニペットを見た他のトピックをしませ検索:

UIGraphicsBeginImageContext(drawingView.bounds.size); 
[drawingView.layer renderInContext:UIGraphicsGetCurrentContext()]; 
UIImage *viewImage = UIGraphicsGetImageFromCurrentImageContext(); 
UIGraphicsEndImageContext(); 
//then display viewImage in another UIImageView... 

それが使用可能だった場合は、それを取得する方法上の任意の手掛かりがアニメーション中に呼ばれますか?

答えて

1

このスニペットはあなたが探しているものではありません。そのスニペットは、現在UIImageとしてコンテキストに表示されているものを保存します。描画にはImageContextを使うことができますが、それは好きではありません。

0

次のキーフレームを実行する前にCAKeyframeAnimationがその代理人に通知するのが理想的です。私はこれが可能だとは思わないので(?)、このようなことをする唯一の方法は、配列の配列を使用し、これを行うために連続したCABasicAnimationインスタンスを使用することです。これは、「貧しい人の」CAKeyframeAnimationのようなものです。このような

何か:この場合

- (void)viewDidLoad 
{ 
    [super viewDidLoad]; 

    _step = 0; 
    _positions = [[NSArray alloc] initWithObjects:[NSValue valueWithCGPoint:CGPointMake(20.0, 20.0)], 
       [NSValue valueWithCGPoint:CGPointMake(40.0, 80.0)], 
       [NSValue valueWithCGPoint:CGPointMake(60.0, 120.0)], 
       [NSValue valueWithCGPoint:CGPointMake(80.0, 160.0)], 
       [NSValue valueWithCGPoint:CGPointMake(100.0, 200.0)], 
       [NSValue valueWithCGPoint:CGPointMake(120.0, 240.0)], 
       [NSValue valueWithCGPoint:CGPointMake(140.0, 280.0)], 
       [NSValue valueWithCGPoint:CGPointMake(160.0, 320.0)], 
       [NSValue valueWithCGPoint:CGPointMake(180.0, 360.0)], 
       [NSValue valueWithCGPoint:CGPointMake(200.0, 400.0)], 
       nil]; 
    [self moveToNextPosition]; 
} 

- (void)moveToNextPosition 
{ 
    if (_step < [_positions count] - 1) 
    { 
     CABasicAnimation *animation = [CABasicAnimation animationWithKeyPath:@"position"]; 
     animation.fromValue = [_positions objectAtIndex:_step]; 
     animation.toValue = [_positions objectAtIndex:(_step + 1)]; 
     animation.delegate = self; 
     animation.removedOnCompletion = YES; 
     [_sprite.layer addAnimation:animation forKey:@"position"]; 

     ++_step; 
    } 
    else 
    { 
     _sprite.center = [[_positions objectAtIndex:_step] CGPointValue]; 
    } 
} 

- (void)animationDidStop:(CAAnimation *)animation finished:(BOOL)finished 
{ 
    UIImageView *trail = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"sprite.png"]]; 
    trail.center = [[_positions objectAtIndex:_step] CGPointValue]; 
    [self.view insertSubview:trail belowSubview:_sprite]; 
    [trail release]; 

    [self moveToNextPosition]; 
} 

、アニメーションは_positionsにNSArrayのIVARで指定された値と、次々に実行し、_stepは、すべてのステップで増分されます。各アニメーションが停止すると、アニメートしているアニメーションの下にスプライトイメージを描画し、移動するポイントがなくなるまでアニメーションを再開します。それから終わりです。

希望すると便利です。