2013-10-07 59 views
0

是否有任何其他API提供將「cameraDevice」更改爲後端和前端? 旁邊的「UIImagePickerController」的cameraDevice屬性?將「cameraDevice」更改爲後端和前端(在UIImagePickerController旁邊)

+0

我猜正在對使用'imagePickerController.cameraDevice = UIImagePickerControllerCameraDeviceRear;' –

+0

是啊,我知道imagePickerController.cameraDevice可變的,但我希望能看到,如果其他API有控制中。由於我的具體原因,我不能使用UIImagePickerController API。 – fkkcloud

+0

比你可以使用[AVCaptureVideoPreviewLayer](https://developer.apple.com/library/mac/documentation/AVFoundation/Reference/AVCaptureVideoPreviewLayer_Class/Reference/Reference.html) –

回答

0

這個功能讓我解決了這個問題。

- (AVCaptureDevice *)frontFacingCamera 
{ 
    NSArray *videoDevices = [AVCaptureDevice devicesWithMediaType:AVMediaTypeVideo]; 
    AVCaptureDevice *captureDevice = nil; 
    for (AVCaptureDevice *device in videoDevices) 
    { 
     if (device.position == AVCaptureDevicePositionFront) { 
      captureDevice = device; 
      break; 
     } 
    } 
    return captureDevice; 
}