1

我正在开发一个iPhone应用程序。我可以选择从相册中选择现有照片。应该有一个快速访问某些图像的选项,就像在iMessage中一样。请查看随附的屏幕截图以获取更多信息。

任何想法 ?

在此处输入图像描述

4

1 回答 1

0

我找到了我的问题的解决方案:

首先,我正在使用下面的相册读取最多 20 张最近的图像code。然后我将所有图像添加到UIScrollView. 最后一个是More。如果用户点击它,它将显示 iPhone 默认"UIImagePickerController"选择其他图像。

如果有人找到更好的解决方案,请发布。

代码

ALAssetsLibrary *library = [[ALAssetsLibrary alloc] init];
[library enumerateGroupsWithTypes:ALAssetsGroupSavedPhotos usingBlock:^(ALAssetsGroup *group, BOOL *stop) {
    [group setAssetsFilter:[ALAssetsFilter allPhotos]];
    [group enumerateAssetsWithOptions:NSEnumerationReverse usingBlock:^(ALAsset *asset, NSUInteger index, BOOL *innerStop) {
        if (asset) {
            if ([self.stackForImages count] >= 20) {
                // Stop the enumerations
                *stop = YES;
                *innerStop = YES;
                [self initializeMedia];
            } else {
                ALAssetRepresentation *representation = [asset defaultRepresentation];
                NSMutableDictionary *workingDictionary = [[NSMutableDictionary alloc] init];
                [workingDictionary setObject:[asset valueForProperty:ALAssetPropertyType] forKey:UIImagePickerControllerMediaType];
                [workingDictionary setObject:[UIImage imageWithCGImage:[asset thumbnail]] forKey:UIImagePickerControllerEditedImage];
                [workingDictionary setObject:[UIImage imageWithCGImage:[representation fullScreenImage]] forKey:UIImagePickerControllerOriginalImage];
                [workingDictionary setObject:[[asset valueForProperty:ALAssetPropertyURLs] valueForKey:[[[asset valueForProperty:ALAssetPropertyURLs] allKeys] objectAtIndex:0]] forKey:UIImagePickerControllerReferenceURL];
                [self.stackForImages addObject:workingDictionary];
            }
        }
    }];
    if ([self.stackForImages count] > 0) {
        [self initializeMedia];
    }
} failureBlock: ^(NSError *error) {
}];
于 2015-06-30T04:07:53.057 回答