我正在为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];
}
答案 0 :(得分:2)
你应该试试MWPhotoBrowser Control by Michael Waterfall
他提供单一和多张照片选择
适用于iOS 5.1.1+。
所有字符串都是可本地化的,因此可以在支持多种语言的应用程序中使用。
答案 1 :(得分:1)
在我的一个项目中,我已经完成了没有ELCImagePickerController的事情。并成功地使用了该代码。在那个项目中,我在图像选择器控制器的导航栏上添加了一个完成按钮。每当您选择一个图像时,您可以使用名为
的方法获取该图像-(void)imagePickerController:(UIImagePickerController *)pickerdidFinishPickingMediaWithInfo:(NSDictionary *)info
每当你完成拾取图像时,你按下那个完成按钮。在那个方法中解除视图控制器。
使用此过程,您可以选择和获取您想要的图像。
我的应用程序正在成功运作。
...干杯!!!!!!!
答案 2 :(得分:1)
在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此方法将为您抓取图像。
不要忘记upvote ...干杯...... !!!!!
答案 3 :(得分:0)
您需要实施这些方法
- (void)elcImagePickerController:(ELCImagePickerController *)picker didFinishPickingMediaWithInfo:(NSArray *)info;
它将返回您选择的图像数组。(控制器发送回一组结构相似的字典)
- (void)elcImagePickerControllerDidCancel:(ELCImagePickerController *)picker;
答案 4 :(得分:0)
试试这个:
- (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;
}
- (无效)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];
}