2012-09-04 80 views
0

我有一個應用程序,使用相機,槍圖像覆蓋以及火和重新加載按鈕。在視網膜iPad和iPhone上,它會在約1秒鐘內循環播放30幀圖像,並在2秒鐘內重播動畫。所有的圖像都是1920 x 1080,在iPhone上它們是1000 x 533。例如,當點擊觸發按鈕時,要循環瀏覽.png,我在PlayViewController.m文件中使用了這個:播放png動畫時的延遲

- (IBAction)fire:(id)sender { 

// Play the firing animation for the rifle, enable reload button 

fireButton.enabled = NO; 
type.animationImages = gunanimload; 
type.animationDuration = 1.0; 
type.animationRepeatCount = 1; 
reloadButton.enabled = YES; 
[type startAnimating]; 

在viewDidLoad方法創建數組,並用圖像加載:

- (void)viewDidLoad 
{ 
[super viewDidLoad]; 

UIImage* img1 = [UIImage imageNamed:@"rev0001.png"]; 

... x30 

gunanimload = [NSArray arrayWithObjects:img1, ... x30, nil]; 

} 

即使它應該被加載陣列當視圖加載時,它仍然似乎是在做它時,消防按鈕被竊聽。我將如何消除這種延遲?還是有一個(相對簡單的)替代玩火和重新加載動畫?

+0

無法理解你的問題 –

回答

1

UIImage imageNamed方法將不會加載圖像,直到它需要顯示爲止。有預先加載圖像的方法。

閱讀以瞭解更多信息: CGImage/UIImage lazily loading on UI thread causes stutter

Non-lazy image loading in iOS

+0

也可以考慮使用精靈,而不是該圖像陣列中。它會提高性能並降低內存要求。 – Resh32

+0

閱讀這個精靈的一個很好的例子:http://mysterycoconut.com/blog/2011/01/cag1/ – Resh32

+0

謝謝,我會研究。 –