UIImagePickerControllerCameraDeviceFront仅每隔两次工作 [英] UIImagePickerControllerCameraDeviceFront only works every other time

查看:77
本文介绍了UIImagePickerControllerCameraDeviceFront仅每隔两次工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的应用中,我默认尝试在 UIImagePicker 中使用前置摄像头。我知道,这似乎很简单...

In my app I'm attempting to use the front camera by default in a UIImagePicker. I know, seems simple enough...

imagePicker.cameraDevice = UIImagePickerControllerCameraDeviceFront;

现在,我第一次启动选择器时一切正常,并且前置摄像头已初始化,但是当选择器被解雇,然后再次显示使用后置摄像头。从那里开始,如果我不断地打开和关闭选择器,则使用的相机将是:前,后,前,后,前,后......

Now, the first time I launch my picker everything works fine and the front camera is initialized, but when the picker is dismissed, and presented again the back camera is used. From there on out if I continuously open and close the picker the camera used will be: front, back, front, back, front, back...

我已经将此代码精简到选择器的基本知识,试图找出问题,并持续存在。有人遇到过这个问题吗?

I've stripped this code down to the bare basics of the picker attempting to isolate the problem and it persists. Has anyone run into this issue before? Any pointers or direction would be greatly appreciated!

编辑:问题已解决!我在 viewDidLoad 中而不是 viewDidAppear中调用 imagePicker = [[UIImagePickerController alloc] init];

Problem solved! I was calling imagePicker = [[UIImagePickerController alloc] init]; in viewDidLoad instead of viewDidAppear!

推荐答案

问题必须在于如何尝试初始化/ present /解雇您的控制器。

The problem must be at how you try to initialize/present/dismiss your controller.

那么,为什么要在相机之间来回切换?

So, why this back and forth between cameras?

由于某些原因,底层的 AVCaptureSession 在关闭控制器后仍保持运行。因此,下次您展示它时,它尝试添加输入,但是它很忙,因此转到下一个可用的(后置摄像头),中断自身(从而释放上一个),等等。

It seems that the underlying AVCaptureSession for some reason kept running after the dismiss of the controller. So the next time you presented it, it tried to add the input but it was bussy, so went to the next available (the rear camera), interrupted itself (thus freeing the previous one) and so on.

这篇关于UIImagePickerControllerCameraDeviceFront仅每隔两次工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆