如何从 Array 为 UIImageView 设置动画

How to animate UIImageView from Array

我有一组图像要制作动画。下面的代码只显示一张图片。仅供参考。 Boothanim、photastaken 和 _arrSlidshowImg 都是 NSMutableArray。我已经尝试了下面代码的所有组合,当拍摄了三张图片时,ImageView 仍然只显示第一张图片。

   for (int i = 0; i < [photostaken count]; i++)
        {

        UIImage *img = [UIImage imageWithData:[_arrSlidshowImg objectAtIndex:i]];
        boothanim =[[NSMutableArray alloc]init];
        [boothanim  addObject:img];

        }
        [self.shareModeOverlayView.boothbg setAnimationImages:boothanim] ;
        self.shareModeOverlayView.boothbg.animationDuration = 1;
        self.shareModeOverlayView.boothbg.animationRepeatCount = 0;
        [self.shareModeOverlayView.boothbg startAnimating];

看起来你每次 for loop 运行时都是 re-initializing 你的 array。你应该 init 你的数组在 for loop 之前。

boothanim =[[NSMutableArray alloc]init];
for (int i = 0; i < [photostaken count]; i++)
{
    UIImage *img = [UIImage imageWithData:[_arrSlidshowImg objectAtIndex:i]];
    [boothanim  addObject:img];
}