2009-05-22 42 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