【问题标题】:Get list of all photo albums and thumbnails for each album获取所有相册的列表和每个相册的缩略图
【发布时间】:2012-03-31 02:52:26
【问题描述】:

如何获取 iOS 中所有相册的列表?我知道图像选择器必须在某个地方列出它们,因为它将它们全部显示给用户。拥有相册后,我将如何显示特定相册中所有图像的缩略图?我似乎在文档中找不到任何内容,但我确信一定有办法做到这一点。

【问题讨论】:

  • 在我的项目中,我得到了一些专辑,它是显示日期而不是名称。我调试我的代码,我发现我的专辑列表包含事件专辑,并且不包含专辑及其名称,如日期。有什么想法可以从我的资产数组中跳过此事件吗?如果你有,请给我解决方案。提前致谢

标签: iphone ios ios5


【解决方案1】:

如果这是您所要求的,您无法从 UIImagePickerController 获得此类信息。

看看AssetsLibrary 框架。甚至还有实现自定义图像选择器的sample code

【讨论】:

  • 在我的项目中,我得到了一些专辑,它是显示日期而不是名称。我调试我的代码,我发现我的专辑列表包含事件专辑,并且不包含专辑及其名称,如日期。有什么想法可以从我的资产数组中跳过此事件吗?如果你有,请给我解决方案。提前致谢
【解决方案2】:

枚举并获取最新图像及其缩略图。

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

// Enumerate just the photos and videos group by using ALAssetsGroupSavedPhotos.
[library enumerateGroupsWithTypes:ALAssetsGroupSavedPhotos usingBlock:^(ALAssetsGroup *group, BOOL *stop) {

    // Within the group enumeration block, filter to enumerate just photos.
    [group setAssetsFilter:[ALAssetsFilter allPhotos]];

    // Chooses the photo at the last index
    [group enumerateAssetsWithOptions:NSEnumerationReverse usingBlock:^(ALAsset *alAsset, NSUInteger index, BOOL *innerStop) {
        // The end of the enumeration is signaled by asset == nil.
        if (alAsset) {
            ALAssetRepresentation *representation = [alAsset defaultRepresentation];
            UIImage *latestPhoto = [UIImage imageWithCGImage:[representation fullScreenImage]];


            UIImage *latestPhotoThumbnail =  [UIImage imageWithCGImage:[alAsset thumbnail]];


            // Stop the enumerations
            *stop = YES; *innerStop = YES;

            // Do something interesting with the AV asset.
            //[self sendTweet:latestPhoto];
        }
    }];
} failureBlock: ^(NSError *error) {
    // Typically you should handle an error more gracefully than this.
    NSLog(@"No groups");
}];

【讨论】:

  • 您可以使用posterImage 这样的[group posterImage] 方法,而不是枚举最新照片,它会为您提供浏览图库时看到的图像的参考,通常是第一张图片跨度>
  • @ibsweek 在我的项目中,我得到一些专辑,它是显示日期而不是名称。我调试我的代码,我发现我的专辑列表包含事件专辑,并且不包含专辑及其名称,如日期。有什么想法可以从我的资产数组中跳过此事件吗?如果你有,请给我解决方案。提前致谢
【解决方案3】:

自 iOS 9.0 起,Assets Library 框架已弃用。相反,请使用 Photos 框架,它在 iOS 8.0 及更高版本中提供了更多功能和更好的性能来处理用户的照片库。

检查Photos 框架,并检查:PHAsset、PHAssetCollection 和 PHCollectionList,具体取决于您的需要。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-02-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多