使用 UIImagePickerController 选择图像后,照片库视图保留在屏幕上

发布于 2024-07-15 19:57:29 字数 1683 浏览 3 评论 0原文

当我通过 UIImagePickerController 界面从照片库中选择一张图片后,即使我在 imagePickerController:didFinishPickingImage:editingInfo 中调用了 dismissModelViewControllerAnimated ,照片库视图仍会保持显示。

有人见过这个吗? 这些是我正在使用的三个相关方法:

- (IBAction)choosePictureFromLibrary:(id)sender {
    if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypePhotoLibrary]) {
        UIImagePickerController* picker = [[UIImagePickerController alloc] init];
        picker.delegate = self;
        picker.allowsImageEditing = YES;
        picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
        [self presentModalViewController:picker animated:YES];
        [picker release];
    }
    else {
        UIAlertView* alert = [[UIAlertView alloc] initWithTitle:@"Error accessing Photo Library" message:@"This device does not support a Photo Library." delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
        [alert show];
        [alert release];
    }
}


- (void)imagePickerController:(UIImagePickerController*)picker didFinishPickingImage:(UIImage*)image editingInfo:(NSDictionary*)editingInfo {   
    UIAlertView* alert = [[UIAlertView alloc] initWithTitle:@"Picture picked!" message:@"You picked a picture!" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
    [alert show];
    [alert release];

    [picker dismissModalViewControllerAnimated:YES];
}


- (void)imagePickerControllerDidCancel:(UIImagePickerController*)picker {   
    [picker dismissModalViewControllerAnimated:YES];
}

我本以为调用 imagePickerController:didFinishPickingImage:editingInfo 会完全关闭照片库视图,但似乎并非如此。 我还需要做些什么才能让它消失吗?

After I choose a picture through the UIImagePickerController interface from the Photo Library, the Photo Library view stays displayed, even though I've called dismissModelViewControllerAnimated in imagePickerController:didFinishPickingImage:editingInfo.

Has anyone seen this? These are the three relevant methods I'm using:

- (IBAction)choosePictureFromLibrary:(id)sender {
    if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypePhotoLibrary]) {
        UIImagePickerController* picker = [[UIImagePickerController alloc] init];
        picker.delegate = self;
        picker.allowsImageEditing = YES;
        picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
        [self presentModalViewController:picker animated:YES];
        [picker release];
    }
    else {
        UIAlertView* alert = [[UIAlertView alloc] initWithTitle:@"Error accessing Photo Library" message:@"This device does not support a Photo Library." delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
        [alert show];
        [alert release];
    }
}


- (void)imagePickerController:(UIImagePickerController*)picker didFinishPickingImage:(UIImage*)image editingInfo:(NSDictionary*)editingInfo {   
    UIAlertView* alert = [[UIAlertView alloc] initWithTitle:@"Picture picked!" message:@"You picked a picture!" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
    [alert show];
    [alert release];

    [picker dismissModalViewControllerAnimated:YES];
}


- (void)imagePickerControllerDidCancel:(UIImagePickerController*)picker {   
    [picker dismissModalViewControllerAnimated:YES];
}

I would have thought that calling imagePickerController:didFinishPickingImage:editingInfo would completely dismiss the Photo Library view, but it doesn't seem to. Is there anything else I have to do to make it go away?

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

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

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

青丝拂面 2024-07-22 19:57:29

您需要访问选择器的 viewController 而不是选择器本身。 试试这条线。

[[picker parentViewController] dismissModalViewControllerAnimated:YES];

You need to access the viewController of the picker not the picker itself. Try this line instead.

[[picker parentViewController] dismissModalViewControllerAnimated:YES];
§普罗旺斯的薰衣草 2024-07-22 19:57:29

您只需调用即可

[self dismissModalViewControllerAnimated:YES];

关闭当前视图顶部的任何模式视图控制器。

这是有道理的,因为您通过调用来呈现视图控制器:

[self presentModalViewController:picker animated:YES];

You can just call

[self dismissModalViewControllerAnimated:YES];

to dismiss any modal view controller on top of the current view.

This makes sense since you present the view controller by calling:

[self presentModalViewController:picker animated:YES];
权谋诡计 2024-07-22 19:57:29

只是对此答案的更新

 [self dismissModalViewControllerAnimated:YES];

已在 iOS 6.0 中弃用,因此您现在需要使用。

 [self dismissViewControllerAnimated:YES completion:nil];

这不是一个巨大的变化,但对于任何看到这个问题并且使用 iOS 6.0 的人来说,他们将需要更新的答案。

 [self presentModalViewController:filePicker animated:YES];

也已被弃用,取而代之的是

 [self presentViewController:filePicker animated:YES completion:nil];

Just an update to the answers to this

 [self dismissModalViewControllerAnimated:YES];

has been deprecated in iOS 6.0 so you now need to use.

 [self dismissViewControllerAnimated:YES completion:nil];

Not a huge change but for anyone that looks at this question and they are using iOS 6.0 they will need an updated answer.

 [self presentModalViewController:filePicker animated:YES];

has also been deprecated in favor of

 [self presentViewController:filePicker animated:YES completion:nil];
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文