我有点困惑,这不是关于如何解雇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的方式,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;
}
答案 0 :(得分:4)
有两种方法对我有用
picker.presentingViewController
代替picker.parentViewController
,由rmaddy imagePickerControllerDidCancel:
,[picker dismissViewControllerAnimated:YES completion:NULL];
以下是完整的代码,它放在呈现UIImagePickerController的UIViewController中:
- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker {
[picker.presentingViewController dismissViewControllerAnimated:YES completion:NULL];
}
答案 1 :(得分:0)
自iOS6以来,方法dismissModalViewControllerAnimated
已被弃用。您使用的新方法是正确的。