2009-05-22 46 views
0

我有一个动画gif(如this之一),当我在iphone应用程序的图像视图中显示时,它只显示第一帧。这种行为与苹果文档一致。 我想知道什么是最好的方式来实现这一点在iphone上?我如何在iphone上显示图像动画

+0

Duplicate http://stackoverflow.com/questions/899472/how-do-i-show-image-animation-on-iphone – ChrisF 2009-05-22 19:07:20

回答

2

这是我在当前项目中获得的一些代码。我有一个循环将图像standy2通过standby7.png到数组中。我使用imageWithContentsOfFile,因为在内存使用上似乎稍微好一点。

standbyAnimationImages = [[NSMutableArray alloc] init]; 
for (NSUInteger i=2; i<=7; i++) { 
    filename = [NSString stringWithFormat:@"standby%d", i]; 
    [standbyAnimationImages addObject:[UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:filename ofType:@"png"]]]; 
} 

imageViewAnimation.animationImages = standbyAnimationImages; 
imageViewAnimation.animationDuration = 2; 
imageViewAnimation.animationRepeatCount = 0; 
[imageViewAnimation startAnimating]; 

希望这可以帮助你。

1

将其拆分为单独的PNG或JPG图像,然后将每个帧加载到UIImageView并使用其动画方法。看看“动画图像”下的UIImageView文档。这非常简单。

0

如果您导出所有帧单独的图像,你可以做一个UIImage视图中,animationImages属性设置为NSArray包含所有帧作为UIImages。然后致电[imageView startAnimating]

Kyle