如何在ios中选择多选图像
Posted
技术标签:
【中文标题】如何在ios中选择多选图像【英文标题】:How to select Multiselection images in ios 【发布时间】:2014-02-10 06:44:54 【问题描述】:我正在为 iPhone 制作一个应用程序,并希望让用户能够从他们的照片库中多选图像。我已经有一个工作代码供用户一次选择四个图像。但我不能一次选择 2 或 3 个图像。我想一次选择 2 或 3 个图像。我正在尝试以下代码。请帮助我任何人。
- (id)initImagePicker
ELCAlbumPickerController *albumPicker = [[ELCAlbumPickerController alloc] initWithStyle:UITableViewStylePlain];
self = [super initWithRootViewController:albumPicker];
if (self)
self.maximumImagesCount = 4;
[albumPicker setParent:self];
else if (self)
self.minimumImageCount=1;
[albumPicker setParent:self];
return self;
- (id)initWithRootViewController:(UIViewController *)rootViewController
self = [super initWithRootViewController:rootViewController];
if (self)
self.maximumImagesCount = 4;
else if (self)
self.minimumImageCount=1;
return self;
-(void)choosePhotoFromExistingImages
ELCImagePickerController *elcPicker = [[ELCImagePickerController alloc] initImagePicker];
elcPicker.maximumImagesCount = 4;
elcPicker.returnsOriginalImage = NO; //Only return the fullScreenImage, not the fullResolutionImage
elcPicker.imagePickerDelegate = self;
[self presentViewController:elcPicker animated:YES completion:nil];
【问题讨论】:
你试过self.maximumImagesCount = 3;尝试在 maximumImagesCount 中将 4 替换为 3 试试下面的链接:***.com/questions/13093143/… 【参考方案1】:你应该试试MWPhotoBrowser Control by Michael Waterfall 他提供了单张和多张照片选择
适用于 ios 5.1.1+。 所有字符串都是可本地化的,因此可以在支持多种语言的应用中使用。
【讨论】:
【参考方案2】:在我的一个项目中,我在没有 ELCImagePickerController 的情况下完成了这件事。并且也成功地处理了该代码。在那个项目中,我在图像选择器控制器的导航栏上添加了一个完成按钮。每当您选择一个图像时,您可以在调用的方法中抓取该图像
-(void)imagePickerController:(UIImagePickerController *)pickerdidFinishPickingMediaWithInfo:(NSDictionary *)info
当您完成选择图像时,您按下完成按钮。在该方法中关闭视图控制器。
使用此过程,您可以选择和获取尽可能多的图像。
我的应用程序运行成功。
干杯....!!!!!!!
【讨论】:
感谢您的回复。请给我任何想法或示例代码。我不知道如何使用 UIImagePickercontroller 选择多个图像【参考方案3】:在uiimagepickercontroller的导航栏添加完成按钮
- (void)navigationController:(UINavigationController *)navigationController
willShowViewController:(UIViewController *)viewController
animated:(BOOL)animated
if (!doneButton)
doneButton = [[UIBarButtonItem alloc] initWithTitle:@"Done"
style:UIBarButtonItemStyleDone
target:self action:@selector(saveImagesDone:)];
viewController.navigationItem.rightBarButtonItem = doneButton;
首先使用 UIImagePickerController 显示图像选择器
抓住你的图片
-(void)imagePickerController:(UIImagePickerController *)picker
didFinishPickingMediaWithInfo:(NSDictionary *)info
NSString *mediaType = [info objectForKey:UIImagePickerControllerMediaType];
if ([mediaType isEqualToString:@"public.image"]
UIImage *image = [info objectForKey:UIImagePickerControllerOriginalImage];
// Get the data for the image
NSData* imageData = UIImageJPEGRepresentation(image, 1.0);
NSArray* paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString* documentsDirectory = [paths objectAtIndex:0];
// Now we get the full path to the file
NSString* fullPathToFile2 = [self createName:documentsDirectory];
// and then we write it out
[imageData writeToFile:fullPathToFile2 atomically:NO];
else
// Show Alert
关闭图像选择器视图控制器
-(IBAction)saveImagesDone:(id)sender
[self dismissViewControllerAnimated:YES completion:nil];
[self loadimages]; // Load your Images
每次点击图片时,
-(void)imagePickerController:(UIImagePickerController *)pickerdidFinishPickingMediaWithInfo:(NSDictionary *)
info 此方法将为您抓取图像。
别忘了点赞……干杯……!!!!!
【讨论】:
【参考方案4】:你需要实现这些方法
- (void)elcImagePickerController:(ELCImagePickerController *)picker didFinishPickingMediaWithInfo:(NSArray *)info;
它将返回您选择的图像数组。(控制器发回一个结构相似的字典数组)
- (void)elcImagePickerControllerDidCancel:(ELCImagePickerController *)picker;
【讨论】:
【参考方案5】:试试这个:
-(id)initImagePicker
ELCAlbumPickerController *albumPicker = [[ELCAlbumPickerController alloc] initWithStyle:UITableViewStylePlain];
self = [super initWithRootViewController:albumPicker];
if (self)
self.maximumImagesCount = 4;
self.returnsImage = YES;
self.returnsOriginalImage = YES;
[albumPicker setParent:self];
self.mediaTypes = @[(NSString *)kUTTypeImage, (NSString *)kUTTypeMovie];
return self;
-(id)initWithRootViewController:(UIViewController *)rootViewController
self = [super initWithRootViewController:rootViewController];
if (self)
self.maximumImagesCount = 4;
self.returnsImage = YES;
return self;
-(void)选择PhotoFromExistingImages
ELCImagePickerController *elcPicker = [[ELCImagePickerController alloc] initImagePicker];
elcPicker.maximumImagesCount = 4;
elcPicker.returnsOriginalImage = NO; //Only return the fullScreenImage, not the fullResolutionImage
elcPicker.imagePickerDelegate = self;
[self presentViewController:elcPicker animated:YES completion:nil];
【讨论】:
以上是关于如何在ios中选择多选图像的主要内容,如果未能解决你的问题,请参考以下文章