Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/25.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
Ios UIImagePickerController-默认情况下,如何访问前置摄像头?_Ios_Objective C_Swift_Camera_Uiimagepickercontroller - Fatal编程技术网

Ios UIImagePickerController-默认情况下,如何访问前置摄像头?

Ios UIImagePickerController-默认情况下,如何访问前置摄像头?,ios,objective-c,swift,camera,uiimagepickercontroller,Ios,Objective C,Swift,Camera,Uiimagepickercontroller,我正在从我的ViewController中使用以下代码启动相机: - (void)viewDidLoad { self.imgPicker = [[UIImagePickerController alloc] init]; self.imgPicker.sourceType = UIImagePickerControllerCameraDeviceFront; self.imgPicker.delegate = self; } - (IBAction)grab

我正在从我的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,但没用

另外,在按下grabCamera后,如何将子视图(半尺寸)添加到此相机的顶部? 如果我在main window.xib中有此子视图,我尝试在说出presentModalViewController代码后只说出addSubview,但它不起作用。。。我是否需要创建一个NSTimer并在完全显示相机显示后加载addSubview,或者我是否需要使用其他东西(类似于CSS中的z索引)第二个问题的答案是imgPicker.cameraOverlayView=viewName


谢谢大家

UIImagePickerControllerCameraDeviceFront
不是
sourceType
属性的有效枚举。
sourceType
属性定义您使用的是相机还是照片库。您需要改为设置
cameraDevice
属性

目标-C 斯威夫特2 斯威夫特3
很好!非常感谢@MattyG是否可以验证UIImagePicker定义的摄像头,以通过一个按钮控制摄像头。例如:`如果(_pickerController.cameraDevice==UIImagePickerControllerCameraDeviceFront){//切换到其他摄像头,反之亦然}您能帮我回答这个问题吗
self.imgPicker.sourceType = UIImagePickerControllerSourceTypeCamera;
self.imgPicker.cameraDevice = UIImagePickerControllerCameraDeviceFront;
imgPicker.sourceType = .Camera
imgPicker.cameraDevice = .Front
imgPicker.sourceType = .camera
imgPicker.cameraDevice = .front