我有点困惑,这不是关于如何关闭 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;
}