2011-06-18 11 views
0

このコードを変更してアニメーションをこのようにするには: image1 - > image2 ---> image3 ---> image4 ---> image 5 ..次にimage1に戻ります 5つの画像を持つCABasicAnimation

...上のコード:私は考えて、その後誰も後半に答え

UIImage *image1 = [UIImage imageNamed:@"1.jpg"]; 
UIImage *image2 = [UIImage imageNamed:@"2.jpg"]; 
UIImage *image3 = [UIImage imageNamed:@"3.jpg"]; 
UIImage *image4 = [UIImage imageNamed:@"4.jpg"]; 
UIImage *image5 = [UIImage imageNamed:@"5.jpg"]; 

NSArray *imageArray = [NSArray arrayWithObjects:image1.CGImage, image2.CGImage, image3.CGImage, nil]; 

//self.introImages.image = image1; 

[self.view addSubview:self.introImages]; 


CABasicAnimation *crossFade = [CABasicAnimation animationWithKeyPath:@"contents"]; 
crossFade.autoreverses = YES; 
crossFade.repeatCount = HUGE_VALF; 
crossFade.duration = 1.0; 
//self.introImages.layer.contents = image2.CGImage; 

crossFade.fromValue = (id)image1.CGImage; 
crossFade.toValue = (id)image5.CGImage; 
[self.introImages.layer addAnimation:crossFade forKey:@"animateContents"]; 

答えて

2

良いです。 :)

コードにいくつか間違いがあります。

まず画像のクロスフェードを使用するには、画像を含むimageViewにアニメーションを追加して、UIImagesを切り替えるだけです。

第2回:アニメーションキューをanimationDidFinishコールバックメソッドの助けを借りて使用するか、UIImageViewクラスのanimationImagesフィールドを使用してUIImageViewに作品。

第3:イメージのレイヤーをimage1からimage5に変更すると、コンパイラーは他のすべての写真を間に入れなければならないことをコンパイラーが予期することができますか?

このコードを試してみてください。

UIImage *image1 = [UIImage imageNamed:@"1.jpg"]; 
UIImage *image2 = [UIImage imageNamed:@"2.jpg"]; 
UIImage *image3 = [UIImage imageNamed:@"3.jpg"]; 
UIImage *image4 = [UIImage imageNamed:@"4.jpg"]; 
UIImage *image5 = [UIImage imageNamed:@"5.jpg"]; 

NSArray *imageArray = [NSArray arrayWithObjects:image1.CGImage, image2.CGImage, image3.CGImage, nil]; 
//imageView to add the array of images you want to cycle through 
iv_introImages.animationImages = imageArray; 
//duration of the animation-cycle 
iv_introImages.animationDuration = 1.0; 
//how often you want the animation to repeat. 0 stands for endless repetition 
iv_introImages.animationRepeatCount = 0; 
//starts the animation 
[iv_introImages startAnimating]; 

は、このことができます願っています。 Mav

関連する問題