UIImagePickerController - 默认情况下如何访问前置摄像头? [英] UIImagePickerController - How do I access the front facing camera by default?
问题描述
我使用ViewController中的以下代码调出相机:
I am bringing up the camera with the following code from my ViewController:
- (void)viewDidLoad {
self.imgPicker = [[UIImagePickerController alloc] init];
self.imgPicker.sourceType = UIImagePickerControllerCameraDeviceFront;
self.imgPicker.delegate = self;
}
- (IBAction)grabCamera {
[self presentModalViewController:self.imgPicker animated:YES];
}
我怎样才能使摄像机默认使用前置摄像头iPhone4而不是后置摄像头?我试过DeviceFront无济于事。
How can I make it so the camera by default uses the front camera of the iPhone4 and not the back camera? I tried DeviceFront to no avail.
另外,在按下grabCamera之后,如何在此相机的顶部添加子视图(半尺寸)? 第二个问题的答案是imgPicker.cameraOverlayView = viewName;
如果我在我的MainWindow.xib中有这个子视图我在说完presentModalViewController代码后尝试说addSubview但它没有用...我需要创建一个NSTimer并在摄像头显示完全后加载addSubview我需要使用别的东西(类似于CSS中的z-index)
Also, How can I add a subview (half sized) ontop of this camera after grabCamera is pressed?
If I have this subview in my MainWindow.xib I tried just saying addSubview after saying the presentModalViewController code but it didn't work... Do I need to create an NSTimer and load the addSubview after the camera display is fully presented or do I need to use something else (similar to z-index in CSS) The answer to the second question is imgPicker.cameraOverlayView = viewName;
谢谢大家!
推荐答案
UIImagePickerControllerCameraDeviceFront
不是<的有效枚举code> sourceType 属性。 sourceType
属性定义您是使用相机还是照片库。您需要设置 cameraDevice
属性。
UIImagePickerControllerCameraDeviceFront
is not a valid enum for the sourceType
property. The sourceType
property defines whether you're using the camera or the photo library. You need to set the cameraDevice
property instead.
self.imgPicker.sourceType = UIImagePickerControllerSourceTypeCamera;
self.imgPicker.cameraDevice = UIImagePickerControllerCameraDeviceFront;
Swift 2
Swift 2
imgPicker.sourceType = .Camera
imgPicker.cameraDevice = .Front
Swift 3
Swift 3
imgPicker.sourceType = .camera
imgPicker.cameraDevice = .front
这篇关于UIImagePickerController - 默认情况下如何访问前置摄像头?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!