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

    - (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

最佳答案

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。

10-08 11:51