Performance 为什么';是否更新我的UIView并显示中间结果?

Performance 为什么';是否更新我的UIView并显示中间结果?,performance,uiimage,dispatch-async,Performance,Uiimage,Dispatch Async,在我的应用程序中,我希望将大量(相同的PNG)文件堆叠在一起,并向用户显示图像结果和进度条。为了提高性能,我编写了以下代码,但只有当for循环完成时,我才能看到最终结果。 对于大型图像集,这不是我想要的,我真的希望看到中间结果。以下代码可能包含错误,但我尚未找到: - (IBAction)doDrawLayers:(NSArray *)drawImages { // Use dispath-queues for drawing intermediate result and progre

在我的应用程序中,我希望将大量(相同的PNG)文件堆叠在一起,并向用户显示图像结果和进度条。为了提高性能,我编写了以下代码,但只有当for循环完成时,我才能看到最终结果。 对于大型图像集,这不是我想要的,我真的希望看到中间结果。以下代码可能包含错误,但我尚未找到:

- (IBAction)doDrawLayers:(NSArray *)drawImages
{
    // Use dispath-queues for drawing intermediate result and progress. 
    _startDrawing = [NSDate date];
    dispatch_queue_t calcImage = dispatch_queue_create("calcImage", NULL);
    dispatch_async(calcImage, ^{
        _sldProgress.maximumValue = drawImages.count;
        _sldProgress.minimumValue = 0;
        _imageNr = 0;
        [_sldProgress setMaximumValue:drawImages.count];
        for (NSString *imageFile in drawImages) {
            @autoreleasepool {
                // Update in main queue.
                dispatch_async(dispatch_get_main_queue(), ^{
                    UIGraphicsBeginImageContext(_imageSize);
                    // Show progress update.
                    _lblProgress.text = [NSString stringWithFormat:@"%d %.2f sec", ++_imageNr, -[_startDrawing timeIntervalSinceNow]];
                    _sldProgress.value = _imageNr;
                    NSString *filePath = [[NSBundle mainBundle] pathForResource:imageFile ofType:nil];
                    [[UIImage imageWithContentsOfFile:filePath] drawAtPoint:CGPointMake(0., 0.)];
                    // Get CGImage from the offscreen image context.
                    _imageView.image = UIGraphicsGetImageFromCurrentImageContext();
                    UIGraphicsEndImageContext();
                });
            }
        }
    });
    // Finished calculating image, release dispatch.
    dispatch_release(calcImage);
}

我还一直在努力解决以下问题:UIGraphicsBeginImageContext/UIGraphicsSendImageContext对的最佳放置位置是什么,因为我希望最小化所使用的内存量并最大限度地提高整体性能。

最终通过合并苹果PhotoScroller(主要基于CATiledLayer)的代码找到了解决方案和大图像缩小示例代码