【发布时间】:2015-09-02 09:09:26
【问题描述】:
我正在开发一个 iPhone 应用程序。我可以选择从相册中选择现有照片。应该有一个快速访问某些图像的选项,就像在 iMessage 中一样。请查看随附的屏幕截图以获取更多信息。
有什么想法吗?
【问题讨论】:
标签: iphone image photo imessage
我正在开发一个 iPhone 应用程序。我可以选择从相册中选择现有照片。应该有一个快速访问某些图像的选项,就像在 iMessage 中一样。请查看随附的屏幕截图以获取更多信息。
有什么想法吗?
【问题讨论】:
标签: iphone image photo imessage
我找到了我的问题的解决方案:
首先,我使用下面的code 从相册中读取最多 20 张最近的图像。然后我将所有图像添加到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) {
}];
【讨论】: