簡體   English   中英

如何在iPhone上顯示圖像動畫

[英]How do i show image animation on iphone

我有一個動畫的gif(像這樣 ),當我在iphone應用程序的圖像視圖中顯示時,它只顯示第一幀。 此行為與Apple文檔一致。 我想知道在iPhone上實現此目標的最佳方法是什么?

這是我在當前項目中獲得的一些代碼。 我有一個循環,可將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];

希望這對您有所幫助。

將其拆分為單獨的PNG或JPG圖像,然后將每個幀加載到UIImageView並使用其動畫方法。 在“動畫圖像”下查看UIImageView文檔。 這很簡單。

如果將所有框架導出到單個圖像,則可以創建UIImage視圖,請將animationImages屬性設置為包含所有框架作為UIImagesNSArray 然后調用[imageView startAnimating]

凱爾

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM