Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/24.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Objective c 如何让iPad上的摄像头在超控器内工作?_Objective C_Xcode_Ipad_Uiimagepickercontroller_Uipopovercontroller - Fatal编程技术网

Objective c 如何让iPad上的摄像头在超控器内工作?

Objective c 如何让iPad上的摄像头在超控器内工作?,objective-c,xcode,ipad,uiimagepickercontroller,uipopovercontroller,Objective C,Xcode,Ipad,Uiimagepickercontroller,Uipopovercontroller,我正在尝试编写iOS应用程序,使用相机或照片库拍照。这是我的第一个iOS应用程序,所以我没有经验。我已经找到了几个例子来说明如何在iPhone上实现这一点,并将模态窗口调用presentViewController替换为IUPopoverController。这对于照片库imagePicker.sourceType=UIImagePickerControllerSourceTypePhotoLibrary很好,但对于camera imagePicker.sourceType=UIImagePic

我正在尝试编写iOS应用程序,使用相机或照片库拍照。这是我的第一个iOS应用程序,所以我没有经验。我已经找到了几个例子来说明如何在iPhone上实现这一点,并将模态窗口调用presentViewController替换为IUPopoverController。这对于照片库imagePicker.sourceType=UIImagePickerControllerSourceTypePhotoLibrary很好,但对于camera imagePicker.sourceType=UIImagePickerControllerSourceTypeCamera,则存在以下错误:

Terminating app due to uncaught exception 'NSGenericException', reason: 'The content view controller argument must be the root of its associated view controller hierarchy.'
使用Xcode 4.6 iOS 6.1的测试

我的代码:

- (void) useCamera:(id)sender
{
    if ([UIImagePickerController isSourceTypeAvailable:
         UIImagePickerControllerSourceTypeCamera])
    {
        UIImagePickerController *imagePicker =
        [[UIImagePickerController alloc] init];
        imagePicker.delegate = self;
        imagePicker.sourceType =
        UIImagePickerControllerSourceTypeCamera;
        imagePicker.mediaTypes = @[(NSString *) kUTTypeImage];
        imagePicker.allowsEditing = NO;

        if(UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
        {
            _popover = [[UIPopoverController alloc] initWithContentViewController: imagePicker];
            [_popover presentPopoverFromRect: _popoverCenter inView:self.view permittedArrowDirections:UIPopoverArrowDirectionUp animated:YES];
        }
        else
        {
            [self presentViewController:imagePicker
                               animated:YES completion:nil];
        }

        _newMedia = YES;
    }
    else
    {
        UIAlertView *alert = [[UIAlertView alloc]
                              initWithTitle: @"Camera failed to open"
                              message: @"Camera is not available"
                              delegate: nil
                              cancelButtonTitle:@"OK"
                              otherButtonTitles:nil];
        [alert show];
    }
}
可以在iPad上显示popover内的摄像头吗?
谢谢

以下回答了OP关于如何在iPad上全屏显示摄像头的评论

将代码更改为:

- (void) useCamera:(id)sender
{
    if ([UIImagePickerController isSourceTypeAvailable:
         UIImagePickerControllerSourceTypeCamera])
    {
        UIImagePickerController *imagePicker =
        [[UIImagePickerController alloc] init];
        imagePicker.delegate = self;
        imagePicker.sourceType =
        UIImagePickerControllerSourceTypeCamera;
        imagePicker.mediaTypes = @[(NSString *) kUTTypeImage];
        imagePicker.allowsEditing = NO;
        imagePicker.modalPresentationStyle = UIModalPresentationFullScreen;

        [self presentViewController:imagePicker
                           animated:YES completion:nil];

        _newMedia = YES;
    }
    else
    {
        UIAlertView *alert = [[UIAlertView alloc]
                              initWithTitle: @"Camera failed to open"
                              message: @"Camera is not available"
                              delegate: nil
                              cancelButtonTitle:@"OK"
                              otherButtonTitles:nil];
        [alert show];
    }
}

以下是OP关于如何在iPad上全屏显示摄像头的评论

将代码更改为:

- (void) useCamera:(id)sender
{
    if ([UIImagePickerController isSourceTypeAvailable:
         UIImagePickerControllerSourceTypeCamera])
    {
        UIImagePickerController *imagePicker =
        [[UIImagePickerController alloc] init];
        imagePicker.delegate = self;
        imagePicker.sourceType =
        UIImagePickerControllerSourceTypeCamera;
        imagePicker.mediaTypes = @[(NSString *) kUTTypeImage];
        imagePicker.allowsEditing = NO;
        imagePicker.modalPresentationStyle = UIModalPresentationFullScreen;

        [self presentViewController:imagePicker
                           animated:YES completion:nil];

        _newMedia = YES;
    }
    else
    {
        UIAlertView *alert = [[UIAlertView alloc]
                              initWithTitle: @"Camera failed to open"
                              message: @"Camera is not available"
                              delegate: nil
                              cancelButtonTitle:@"OK"
                              otherButtonTitles:nil];
        [alert show];
    }
}

你所拥有的应该很好用。但是,大多数人更希望您将相机显示为全屏视图。虽然源类型不是camera的UIImagePickerViewController必须位于iPad上的popover中,但摄像头可以像iPhone上一样显示在全屏模式视图控制器中。@rmaddy如何在iPad上启动全屏模式视图控制器?由于iPhone、iPad和iOS版本之间的差异,网络上出现了混乱。你所拥有的应该可以正常工作。但是,大多数人更希望您将相机显示为全屏视图。虽然源类型不是camera的UIImagePickerViewController必须位于iPad上的popover中,但摄像头可以像iPhone上一样显示在全屏模式视图控制器中。@rmaddy如何在iPad上启动全屏模式视图控制器?由于iPhone、iPad和iOS版本之间的差异,网络上乱七八糟。我现在无法在真正的设备上尝试,但在iPad模拟器上,我有以下错误:**由于未捕获的异常“NSInvalidArgumentException”而终止应用程序,原因:'在iPad上,UIImagePickerController必须通过UIPopoverController显示,该错误仅在图像选择器源类型不是UIImagePickerController源类型Camera时出现。对于非摄像头类型,您必须在iPad上使用popover。由于模拟器没有摄像头,您不能在模拟器中测试我的答案。谢谢。我明天将在该设备上尝试。我现在无法在真实设备上尝试,但在iPad模拟器上我出现以下错误:**由于未捕获的异常“NSInvalidArgumentException”而终止应用程序,原因:'在iPad上,UIImagePickerController必须通过UIPopoverController显示,该错误仅在图像选择器源类型不是UIImagePickerController源类型Camera时出现。对于非摄像头类型,您必须在iPad上使用popover。由于模拟器没有摄像头,您不能在模拟器中测试我的答案。谢谢。我明天试试这个设备。