0
我有7個圖像,我試圖淡入/出1 ImageView。我已經將所有圖像存儲在一個數組中,然後有一個循環來顯示每個圖像並淡入下一個,但是,當我運行程序時,只顯示最後2張圖像。任何想法,爲什麼這是?以及如何解決它?代碼如下。與UIImageView上的動畫故障
imageArray = [NSArray arrayWithObjects:
[UIImage imageNamed:@"image 0.jpg"],
[UIImage imageNamed:@"image 1.jpg"],
[UIImage imageNamed:@"image 2.jpg"],
[UIImage imageNamed:@"image 3.jpg"],
[UIImage imageNamed:@"image 4.jpg"],
[UIImage imageNamed:@"image 5.jpg"],
[UIImage imageNamed:@"image 6.jpg"],
nil];
self.imageview.backgroundColor = [UIColor blackColor];
self.imageview.clipsToBounds = YES;
int count = [imageArray count];
for (int i = 0; i <count-1 ; i++)
{
UIImage *currentImage = [imageArray objectAtIndex: i];
UIImage *nextImage = [imageArray objectAtIndex: i +1];
self.imageview.image = [imageArray objectAtIndex: i];
[self.view addSubview:self.imageview];
CABasicAnimation *crossFade = [CABasicAnimation animationWithKeyPath:@"contents"];
crossFade.duration = 5.0;
crossFade.fromValue = (__bridge id)(currentImage.CGImage);
crossFade.toValue = (__bridge id)(nextImage.CGImage);
[self.imageview.layer addAnimation:crossFade forKey:@"animateContents"];
self.imageview.image = nextImage;
};