我在从 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 addObjecthotoThumbnail];
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/
欢迎光临 OStack程序员社区-中国程序员成长平台 (https://ostack.cn/) | Powered by Discuz! X3.4 |