应用程序打开时启动了后置摄像头

时间:2013-09-10 04:11:59

标签: iphone objective-c camera uiimagepickercontroller launch

当应用程序成功启动时,让后置摄像头运行的最佳方法是什么?

我希望我的应用首先使用模态视图控制器打开,这样用户可以在不想拍摄照片的情况下关闭相机。

谢谢!

编辑:

我已经弄清楚了......这比制作它容易得多!

- (void)viewDidLoad
{
    self.UIPicker = [[UIImagePickerController alloc] init];
    self.UIPicker.delegate = self;
    self.UIPicker.sourceType = UIImagePickerControllerSourceTypeCamera;

    [self launchCamera];
}

- (void)launchCamera
{
    if([UIImagePickerController isCameraDeviceAvailable:UIImagePickerControllerCameraDeviceRear])
    {
        self.UIPicker.cameraDevice =  UIImagePickerControllerCameraDeviceRear;
        [self presentViewController:self.UIPicker animated:NO completion:nil];
    }
    else
    {
        self.UIPicker.cameraDevice =  UIImagePickerControllerCameraDeviceFront;
        [self presentViewController:self.UIPicker animated:NO completion:nil];
    }
}

// image picker delegate code here

另一个问题是:

我正在使用自定义叠加层,但原生“快门”图形仍然显示。如何删除或隐藏它?

谢谢!

1 个答案:

答案 0 :(得分:2)

使用以下条件

if([UIImagePickerController isCameraDeviceAvailable:UIImagePickerControllerCameraDeviceRear]) 
{
    imagePickerController.cameraDevice =  UIImagePickerControllerCameraDeviceRear;
}
else 
{
    imagePickerController.cameraDevice =  UIImagePickerControllerCameraDeviceFront;
}