iPhone:如何设置一系列图像的动画?哪种方法是最好的?

iPhone:如何设置一系列图像的动画?哪种方法是最好的?,iphone,objective-c,cocoa-touch,ios4,cocos2d-iphone,Iphone,Objective C,Cocoa Touch,Ios4,Cocos2d Iphone,我想在我的应用程序中设置一系列图像的动画 我找到了以下动画代码: imgView.animationImages = [NSArray arrayWithObjects: [UIImage imageNamed:@"4.png"], [UIImage imageNamed:@"4.png"], [UIImage imageName

我想在我的应用程序中设置一系列图像的动画

我找到了以下动画代码:

 imgView.animationImages = [NSArray arrayWithObjects:  
                           [UIImage imageNamed:@"4.png"],
                           [UIImage imageNamed:@"4.png"],
                           [UIImage imageNamed:@"4.png"],
                           [UIImage imageNamed:@"3.png"],
                           [UIImage imageNamed:@"3.png"],
                           [UIImage imageNamed:@"3.png"],
                           [UIImage imageNamed:@"2.png"],
                           [UIImage imageNamed:@"2.png"],
                           [UIImage imageNamed:@"1.png"],
                           [UIImage imageNamed:@"1.png"],

                           nil];
imgView.animationDuration = 3.00;
imgView.animationRepeatCount = 1.0; 
[imgView startAnimating];
但是当我们有更少的图像来制作动画时,上面的代码是很好的。否则会降低应用程序的性能

然而,我必须动画太多的图像


那么,另一种选择是什么呢?哪种方法最好?

最简单的方法是将NSMutableArray子类化,它会报告总帧数并根据需要加载/发布图像。

有任何示例或更多详细信息吗?您告诉我的是相同的方法,但将其替换为NSMutableArray??我的意思是您编写了NSMutableArray的子类,覆盖count以报告帧,并根据需要加载getObjectAt。我手头没有样本。如果这个问题是针对cocos2d iphone的,为什么不使用cocos2d iphone的动画功能?特别是cocos2d缓存每个纹理,这样它将只加载一次,如果使用UIImage,我不确定这一点。为了获得最佳动画性能,您当然希望使用cocos2d而不是图像视图为帧设置动画。可能的重复
-(void)animationImageChange:(NSString *)imageName{

NSString* imagePath=[[NSBundle mainBundle] pathForResource:imageName ofType:@"jpg"];
[backgroundImage setImage:[UIImage imageWithContentsOfFile:imagePath]];

}

- (void)viewDidLoad {
    [super viewDidLoad];

     doorNumberImage=0;
 timer=[NSTimer scheduledTimerWithTimeInterval:0.1f
                                         target:self
                                       selector:@selector(startAnimation)
                                       userInfo:nil
                                        repeats:YES];

}

-(void)startAnimation{
   [self doorAnimationImageChange:[NSString stringWithFormat:@"%d",doorNumberImage]];
    doorNumberImage=doorNumberImage+1;
}