从已呈现的 UIViewController 呈现 UIImagePickerController

Present UIImagePickerController from UIViewController that is already presented

提问人:kanso 提问时间:9/25/2020 更新时间:9/25/2020 访问量:1525

问:

我创建了一个设置/编辑类型的视图控制器,如下所示:

    EditViewController *editController = [storyboard instantiateViewControllerWithIdentifier:@"parent"];
    UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:editController];
    editController.delegate = self;
    navController.modalPresentationStyle = UIModalPresentationPopover;
    [self presentViewController:navController animated:YES completion:nil];

注意:EditViewController 是 UITableViewController 的子类,而“self”只是主导航视图控制器。

现在,从这个呈现的导航控制器/视图控制器中,有一个 UIImageView,用户可以选择通过从相机拍摄照片来填充,他们通过按钮操作来完成:

- (IBAction)takePhotoForImageView:(UIButton *)sender {    
    UIImagePickerController *picker = [[UIImagePickerController alloc] init];
    picker.delegate = self;
    picker.allowsEditing = YES;
    picker.sourceType = UIImagePickerControllerSourceTypeCamera;
    picker.cameraDevice = UIImagePickerControllerCameraDeviceRear;
    picker.modalPresentationStyle = UIModalPresentationFullScreen;

    [self showViewController:picker sender:self];
//    [self presentViewController:picker animated:YES completion:nil];
}

代码运行而不会崩溃,但我在调试器中得到以下信息:

[Camera] Failed to read exposureBiasesByMode dictionary: Error Domain=NSCocoaErrorDomain 
Code=4864 "*** -[NSKeyedUnarchiver _initForReadingFromData:error:throwLegacyExceptions:]: data
 is NULL" UserInfo={NSDebugDescription=*** -[NSKeyedUnarchiver
 _initForReadingFromData:error:throwLegacyExceptions:]: data is NULL}

[Presentation] Attempt to present <UIImagePickerController: 0x11d00fe00> on 
<UINavigationController: 0x11e009c00> (from <EditViewController: 0x11d010c00>) 
while a presentation is in progress.

我不知道第一个错误,但假设它与第二个错误有关。

对于第二个错误/警告(?),在显示UIImagePickerController之前关闭第一个显示的控制器不是一个选项。

所以问题是:从另一个视图控制器中启动 UIImagePickerController(源类型为 UIImagePickerControllerSourceTypeCamera)的正确方法是什么?

iOS Objective-C Swift UIImagePickerController

评论

0赞 Itay Brenner 9/25/2020
当您在已经存在 VC 时显示 VC 时,第二个警告是正常的,似乎是与相机相关的错误。此警告是否出现在所有设备/模拟器中?exposureBiasesByMode
0赞 Muhammed Ayaz 10/11/2020
@ItayBrenner即使我在 iOS14 中也面临同样的问题。而且有些时间选择器不是压缩视频。

答: 暂无答案