2

我有一个使用 Quartz 处理几个图像的应用程序,我希望有一个 UIProgressView 在每次操作后都会发生变化。(例如 0.0 0.2 0.4 0.6 0.8 1.0)

问题是,似乎在处理我的图像时,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。非常感谢您的反馈或经验或此。

谢谢
夏。

4

1 回答 1

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];

}
于 2011-09-02T11:19:09.080 回答