[英]iOS - UIImageView Animation receiving memory warning
我試圖運行兩個UImageView,它們具有多個動畫數組,它們會根據用戶的選擇進行加載和動畫處理。 例如,這是一種方法:
-(void)initiateAnimations {
nullAnimation = [NSArray arrayWithObjects:
[UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"null0002" ofType:@"png"]],
[UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"null0003" ofType:@"png"]],
[UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"null0004" ofType:@"png"]],
[UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"null0005" ofType:@"png"]],
[UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"null0006" ofType:@"png"]],
[UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"null0007" ofType:@"png"]],
[UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"null0008" ofType:@"png"]],
[UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"null0009" ofType:@"png"]],
[UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"null0010" ofType:@"png"]], nil];
}
這是一個調用動畫方法的IBAction
:
-(IBAction)nullani {
player.animationImages = nullAnimation;
player.animationDuration = 0.50;
player.animationRepeatCount = 1;
[player startAnimating];
}
最初一切都很好,但是請記住,我還有大約5-6個其他動畫數組,它們的圖像大小基本相同。 它們不大,范圍從12-80k .png文件。 幾次嘗試制作動畫時,我在輸出中收到此錯誤:
2013-03-16 01:34:44.438 [3316:907] Received memory warning.
我收到此消息后,加載的任何新動畫都會使應用程序崩潰。 我在Instruments上運行它,但找不到任何泄漏,崩潰時輸出沒有任何幫助。
這里有內存問題嗎? 我如何擺脫這個問題? 謝謝。
一些想法:
1)數組中加載的動畫數量不得超過1個。 停止一個動畫並准備開始另一個動畫后,請刪除第一個動畫,並將觀眾看到的圖像替換為應顯示的單個圖像。 如果您可以確定顯示的確切圖像(對此表示懷疑),則可以用單個圖像替換陣列,並且該圖像不會閃爍。
2)如果您無法執行1),請嘗試直接使用Core Animation(為您做更多工作),然后自己制作動畫。 這使您可以更好地控制內存使用情況(您可以在文件系統上緩存圖像位圖)。
3)使用Mac和AVFoundation或QTKit,從圖像制作動畫,然后創建一個開始和停止而不是圖像序列的“電影”。 在這種情況下,您可以用電影對象替換捆綁包中的靜態圖像。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.