2012-04-27 6 views
0

画像を1つずつスクロールする必要があります。以下は私が使用しているコードですCABasicAnimationを使用して画像の配列をスクロール

_imageViewはUIImageViewで、imagesArrayはオブジェクトの配列を持つNSArrayです。

_imageView.animationImages=imagesArray; 
  _imageView.animationDuration=10; 
   [_imageView startAnimating]; 
     
   CABasicAnimation *scrollText; 
   scrollText=[CABasicAnimation animationWithKeyPath:@"position.x"]; 
   scrollText.duration = 10.0; 
   scrollText.speed= 3; 
   scrollText.repeatCount = 0; 
   scrollText.autoreverses = NO; 
    
   scrollText.fromValue = [NSNumber numberWithFloat:500]; 
   scrollText.toValue = [NSNumber numberWithFloat:-200.0]; 
    
   [[_imageView layer] addAnimation:scrollText forKey:@"scrollTextKey"]; 

私は画像がスクロールしていて、それが1つずつ変化しているのが分かります。 しかし、これらの画像は無関係に変化しています。フレーム/スクリーンから画像を1枚ずつ変更したいのですが。いずれかのアイデアを提案することはできますか?

答えて

1

私はあなたが何を求めているのかよく分かりません。アニメーションを作成して、一連のイメージが画面の下部から始まり、アニメーションを上から上に、画面からアニメーションを作成したいと言っていると思います。

これを行うには、画像を下側のオフスクリーンから上側のオフスクリーンにアニメーションするアニメーションを作成し、そのアニメーションをさまざまな画像で数回ループさせたいと思うでしょう。このようなもの。

インスタンス変数imageNumberを定義します。これをゼロに設定し、animateImage(下)を呼び出してアニメーションを開始します。

-(void) animateImage; 
{ 
    _imageView.image = [imagesArray objectAtIndex: imageNumber]; 
    CGPoint imageCenter = _imageView.center; 
    imageCenter.y = 500; 
    _imageView.center = imageCenter; 
    [UIView animateWithDuration: 10 
    delay: 0.0 
    options: UIViewAnimationOptionCurveLinear 
    animations: 
    ^{ 
     CGPoint newImageCenter = _imageView.center; 
     newImageCenter.y = -200; 
     _imageView.center = imageCenter; 
    completion: 
    ^{ 
     imageNumber++; 
     if (imageNumber < [imagesArray count]) 
     [self animateImage]; 
    } 
    ]; 
} 
+0

ありがとう:

コードは次のようになります。それは私を助けるだろう。私はそれをCALayerとCABasicAnimationを使って実現しました。私はこの方法も試してみます.LOCは非常に少ないです。再度、感謝します。 – Perseus

+0

LOC =コード行? –

関連する問題