将滚动视图堆叠到 UIImagePickerController 上

发布于 2024-08-29 05:43:44 字数 2041 浏览 2 评论 0原文

我首先想说的是,除了教程示例之外,我对任何东西都有点陌生,如果这是一个愚蠢的问题,我很抱歉。

我稍微修改了一些示例代码,这样一旦用户选择了图像,它就不会关闭 UIImagePickerController,而是在后台处理它。

这似乎工作得很好,但是一旦用户选择了他们想要处理的所有图像,他们看到的唯一按钮就是“取消”。

我希望更改代码,以便将所选图像添加到图像选择器底部的滚动视图中,但找不到将任何内容堆叠或覆盖到 UIImagePickerController 视图上的方法。

到目前为止我的代码如下:

-(IBAction)LoadPhotoAlbums:(id)sender
{
NSLog(@"LoadPhotoAlbums");
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; 

if (![UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypePhotoLibrary]) {
    return;
}

if(photoPicker == NULL) {
    photoPicker = [[UIImagePickerController alloc] init];
    photoPicker.delegate = self;
    photoPicker.allowsImageEditing = NO;
}

photoPicker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;


[self presentModalViewController:photoPicker animated:YES];
[pool release];
}



- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{

    if([[info objectForKey:@"UIImagePickerControllerMediaType"] isEqualToString:K_UI_TYPE_IMAGE])
    {
        NSLog(@"Image Selected");
        selectedImage = [info objectForKey:@"UIImagePickerControllerOriginalImage"];
        NSDateFormatter *dateFormatter = [[[NSDateFormatter alloc] init] autorelease];
        [dateFormatter setDateFormat:@"ddMMMyyyyHHmmss"];
        NSString *date = [dateFormatter stringFromDate:[NSDate date]];

        NSData *imageData = UIImageJPEGRepresentation(selectedImage,0.9);

        NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
        selectedImagePath = [[paths objectAtIndex:0] stringByAppendingPathComponent:[NSString stringWithFormat:@"%@.jpg", date]];
        NSLog(@"Image path is %@", selectedImagePath);

        if([imageData writeToFile:selectedImagePath atomically:YES])
            NSLog(@"Write Successful");
    }

    //[picker dismissModalViewControllerAnimated:YES];
    //add to listofimages view.
    [self uploadSelectedImage];
}

I'd like to first say I'm a little new to anything but tutorial examples, so sorry if this is a daft question.

I have modified some sample code ever so slightly so that instead of closing a UIImagePickerController once the user has picked an image it processes it in the background.

This seems to work quite well, but once the user has picked all of the images they want to process the only button they're presented with is "Cancel".

I was hoping to change the code so that it adds the selected image to a scrolling view at the bottom of the image picker, but can't find a way to stack or overlay anything onto the UIImagePickerController view.

The code I have so far is below:

-(IBAction)LoadPhotoAlbums:(id)sender
{
NSLog(@"LoadPhotoAlbums");
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; 

if (![UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypePhotoLibrary]) {
    return;
}

if(photoPicker == NULL) {
    photoPicker = [[UIImagePickerController alloc] init];
    photoPicker.delegate = self;
    photoPicker.allowsImageEditing = NO;
}

photoPicker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;


[self presentModalViewController:photoPicker animated:YES];
[pool release];
}



- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{

    if([[info objectForKey:@"UIImagePickerControllerMediaType"] isEqualToString:K_UI_TYPE_IMAGE])
    {
        NSLog(@"Image Selected");
        selectedImage = [info objectForKey:@"UIImagePickerControllerOriginalImage"];
        NSDateFormatter *dateFormatter = [[[NSDateFormatter alloc] init] autorelease];
        [dateFormatter setDateFormat:@"ddMMMyyyyHHmmss"];
        NSString *date = [dateFormatter stringFromDate:[NSDate date]];

        NSData *imageData = UIImageJPEGRepresentation(selectedImage,0.9);

        NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
        selectedImagePath = [[paths objectAtIndex:0] stringByAppendingPathComponent:[NSString stringWithFormat:@"%@.jpg", date]];
        NSLog(@"Image path is %@", selectedImagePath);

        if([imageData writeToFile:selectedImagePath atomically:YES])
            NSLog(@"Write Successful");
    }

    //[picker dismissModalViewControllerAnimated:YES];
    //add to listofimages view.
    [self uploadSelectedImage];
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文