0

我有点困惑,这不是关于如何关闭 UIImagePickerController 的问题,它更像是“为什么会这样”类型的问题。我在 iOS7 中工作。

在线查看苹果文档(此链接:https ://developer.apple.com/library/ios/documentation/AudioVideo/Conceptual/CameraAndPhotoLib_TopicsForIOS/Articles/TakingPicturesAndMovies.html#//apple_ref/doc/uid/TP40010406-SW6 ) ,我遇到了以下关闭 UIImagePickerController 的代码:

[[picker parentViewController] dismissModalViewControllerAnimated: YES];

编辑:我知道该方法已被弃用,因此我尝试了以下方法,但这也不起作用:

[[picker parentViewController] dismissViewControllerAnimated:YES completion:NULL];

那些对我不起作用。然而,这确实有效:

[picker dismissViewControllerAnimated:YES completion:NULL];
  • 苹果文档有错吗?还是刚刚过时?
  • 为什么第二段代码有效,因为据我了解,它是父视图控制器的工作,可以消除弹出框之类的内容,或者在本例中为 UIImagePickerController

谢谢你。

编辑:这就是我呈现 UIImagePickerController 的方式,UITapGestureRecognizer 调用第一个方法,然后调用第二个方法。

- (IBAction)captureMoment:(UITapGestureRecognizer *)sender {
    [self startCameraCaptureFromViewController:self usingDelegate:self];
}

- (BOOL)startCameraCaptureFromViewController:(UIViewController *)controller
                               usingDelegate:(id <UIImagePickerControllerDelegate, UINavigationControllerDelegate>)delegate {

    if (delegate == nil || controller == nil || [UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera] == NO) {
        return NO;
    }

    UIImagePickerController *camera = [[UIImagePickerController alloc] init];
    camera.sourceType = UIImagePickerControllerSourceTypeCamera;

    camera.allowsEditing = NO;

    camera.delegate = delegate;

    [controller presentViewController:camera animated:YES completion:NULL];

    return YES;
}
4

2 回答 2

4

有两种方法对我有用

  1. 使用picker.presentingViewController代替picker.parentViewController,由 rmaddy 回答
  2. 在中使用以下代码imagePickerControllerDidCancel:[picker dismissViewControllerAnimated:YES completion:NULL];

这是完整的代码,它被放置在呈现 UIImagePickerController 的 UIViewController 中:

- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker {
    [picker.presentingViewController dismissViewControllerAnimated:YES completion:NULL];
}
于 2013-11-11T03:01:03.790 回答
0

自 iOS6 以来,该方法dismissModalViewControllerAnimated已被弃用。您使用的新方法是正确的。

于 2013-11-10T23:52:49.053 回答