2011-09-02 27 views
2

我有一個應用程序使用Quartz處理一對圖像,並且我希望在每次操作後都有一個UIProgressView。 (例如0.0 0.2 0.4 0.6 0.8 1.0)iOS設置正在處理圖像時的進度條值

問題是,看起來我的圖像正在處理UI完全鎖定,並且值只在所有的過程完成後才改變(意味着它只是達到1.0而不通過子步驟),

你們有沒有遇到過這種情況?

僞:

for(uint i=0;i<5;i++){ 
    // Execute some Quartz based action here, such as CGContextDrawTiledImage etc... 
    myProgress.progress = (i+1) * 0.2;   
} 

因此,實際上不是的進度條每次操作後改變,它只是在最後1.0改變一次。希望您的反饋或經驗或此。

謝謝
Shai。

回答

2

您需要在單獨的線程中更新您的資產或進度欄,以便兩者可以並行更新。

看一看[NSThread detachNewThreadSelector:selector toTarget:target withObject:object];

讓你的進度變量

[NSThread detachNewThreadSelector:@selector(updateFilterProgress) toTarget:self withObject:nil]; 

prgLoader.progress = x; 


- (void) updateFilterProgress{ 

    NSAutoreleasePool *pool = [NSAutoreleasePool new]; 

    while ([prgLoader.progress floatValue] < 1.0f) //Keep this thread alive till done loading. You might want to include a way to escape (a BOOL flag) 
    { 
     GTMLoggerInfo(@"Updating progress to %f", [progress floatValue]); 
     prgLoader.progress = [progress floatValue]; 
    } 
    [pool release]; 

} 
+0

成員只是爲了確保,可以說生病放在一個不同的選擇的myProgress.progress線,並在不同的執行它線?那是你提供的嗎?我會嘗試:)聽起來不錯。 –

+0

是的,我想你已經正確理解了我的建議。 –

+0

嘿,我試過以下沒有成功,我做錯了什麼?還附上日誌:http://pastebin.com/GfCqmq1s –