2

我们尝试将相册中的图片异步加载到不同的 UIImageView。但是现在,经过很大的延迟,所有图像一起加载。

- (void)loadAllAssetWithHandler:(void (^)(ALAsset *))hanlderAssetDidLoad
{
    ALAssetsLibraryAccessFailureBlock blockFailure =  ^(NSError *error){
        NSLog(@"ERROR = %@", error.description);
    };

    ALAssetsLibrary *library = [[ALAssetsLibrary alloc] init];

    void (^assetGroupEnumerator)(ALAssetsGroup *, BOOL *) = ^(ALAssetsGroup *group, BOOL *stop)
    {
        if (group == nil) {
            return;
        }
        if([[group valueForProperty:ALAssetsGroupPropertyName] isEqualToString: @"album"])
        {
            [group enumerateAssetsUsingBlock:^(ALAsset *asset, NSUInteger index, BOOL *stop)
             {
                 if(asset == nil) {
                     return;
                 }
                 hanlderAssetLoad(asset);
             }];
            return;
        }
    };

    // Enumerate Albums
    [library enumerateGroupsWithTypes: ALAssetsGroupAll
                           usingBlock: assetGroupEnumerator
                         failureBlock: blockFailure];
    [library release];    
}

    [self loadAllAssetsWithHandlert:^(ALAsset *asset) {

            UIImageView *imageView = [self nextImageVIew];
            imageView.image = [UIImage imageWithCGImage: asset.defaultRepresentation.fullResolutionImage];  //or thumbnail
        }];

那么,我们如何让图片轮流上传到 UIImageView(每次上传后立即)?

4

0 回答 0