打开自定义相机时出错 (Objective-c)

Error to open Custom Camera (Objective-c)

我尝试制作自定义相机,但它不起作用。我还需要添加一个叠加层,但我不知道如何。有人可以帮助我吗?

    - (IBAction)AbrirCamara:(id)sender {
UIImagePickerController *picker = [UIImagePickerController new];
                                                   picker.delegate = self;

                                                   if([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera])
                                                   {



                                                       picker.cameraCaptureMode = UIImagePickerControllerCameraCaptureModePhoto;
                                                       picker.cameraDevice = UIImagePickerControllerCameraDeviceRear;
                                                       picker.showsCameraControls = NO;
                                                       picker.navigationBarHidden = YES;
                                                       picker.toolbarHidden = YES;
                                                       picker.wantsFullScreenLayout = YES;



                                                       picker.sourceType = UIImagePickerControllerSourceTypeCamera;
                                                       [self presentViewController:picker animated:YES completion:nil];
                                                   }}

这是错误。

      Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Source type must be UIImagePickerControllerSourceTypeCamera'
*** First throw call stack:
(0x2ed43f0b 0x394dace7 0x317cf6d9 0x317cf551 0xdc7e7 0x315a86c7 0x315a8663 0x315a8633 0x31593d7b 0x315a807b 0x3156b541 0x315a3325 0x315a2c4b 0x31577e75 0x31576541 0x2ed0efef 0x2ed0e4b7 0x2ed0cca7 0x2ec77769 0x2ec7754b 0x33be46d3 0x315d6891 0xde565 0x399d8ab7)
libc++abi.dylib: terminating with uncaught exception of type NSException

在分配图像选择器控制器后设置 picker.sourceType = UIImagePickerControllerSourceTypeCamera 并在外部进行其他设置,如 cameraDevicemode 等条件。只需在 if.

中显示该选择器

并确保您已将 UIImagePickerControllerSourceTypeCamera 设置为源类型,因为您的错误似乎是您设置了错误的源类型。

UIImagePickerController *picker = [UIImagePickerController new];
picker.delegate = self;

if([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera])
{

    picker.sourceType = UIImagePickerControllerSourceTypeCamera;
    picker.cameraCaptureMode = UIImagePickerControllerCameraCaptureModePhoto;
    picker.cameraDevice = UIImagePickerControllerCameraDeviceRear;
    picker.showsCameraControls = NO;
    picker.navigationBarHidden = YES;
    picker.toolbarHidden = YES;
    picker.wantsFullScreenLayout = YES;

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

你的问题是你在下面写了 sourceType 发生了错误。 在您设置其他控制器后首先设置 SourceType。