我在从 iPhone (iOS 8.4) 的图像库中选择图像时遇到问题。
这是我的代码:
UIImagePickerController *imagePicker = [[UIImagePickerController alloc] init];
imagePicker.delegate = self;
imagePicker.allowsEditing = NO;
imagePicker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
[self presentModalViewController:imagePicker animated:YES];
但如果我选择一张图片并同时交换该图片,它会打开一个编辑 View ,然后如果我尝试删除该图片,我的应用程序就会崩溃。
它是图片库的默认功能吗?还是可以通过代码来处理?
请告诉我。 提前致谢
最佳答案
如果你可以试试
NSMutableArray *assetGroups = [[NSMutableArray alloc] init];
void (^assetGroupEnumerator) (ALAssetsGroup *, BOOL *) = ^(ALAssetsGroup *group, BOOL *stop)
{
if(group != nil)
{
[group enumerateAssetsUsingBlock:^(ALAsset *result, NSUInteger index, BOOL *stop)
{
//ALAssetRepresentation holds all the information about the asset being accessed.
if(result)
{
ALAssetRepresentation *representation = [result defaultRepresentation];
if (representation !=nil)
{
UIImage *PhotoThumbnail = [UIImage imageWithCGImage:[result thumbnail]];
[fetchedThumbnails addObject:PhotoThumbnail];
UIImage * latestPhoto = [UIImage imageWithCGImage:[result thumbnail]];
[fetchedImages addObject:latestPhoto];
}
}
}];
[assetGroups addObject:group];
}
galleryImagesCV.hidden=NO;
[galleryImagesCV reloadData];
};
assetGroups = [[NSMutableArray alloc] init];
ALAssetsLibrary *library = [[ALAssetsLibrary alloc] init];
NSUInteger groupTypes = ALAssetsGroupSavedPhotos;
[library enumerateGroupsWithTypes:groupTypes usingBlock:assetGroupEnumerator failureBlock:^(NSError *error)
{
NSLog(@"A problem occurred");
}];
导入AssetsLibrary/AssetsLibrary.h
这将为您提供数组中图库中的所有图像。您可以在自定义 View 中显示这些并选择/交换等。
希望对你有帮助
关于ios - 如何防止用户同时从图片库中选择和交换图片,以免进入编辑 View ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37982040/