Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/112.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/23.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 由加速计确定前后摄像头之间的切换_Ios_Objective C_Ios6_Camera_Accelerometer - Fatal编程技术网

Ios 由加速计确定前后摄像头之间的切换

Ios 由加速计确定前后摄像头之间的切换,ios,objective-c,ios6,camera,accelerometer,Ios,Objective C,Ios6,Camera,Accelerometer,我正试图使用UIC加速度计在Objective-C的前后摄像头之间切换。基本上,如果设备正面朝上,我希望后面的摄像头打开。如果设备正面朝下(屏幕朝下),我希望前摄像头处于活动状态。解决这个问题的最好办法是什么?我正在通过AVFoundation访问摄像头。谢谢 我在我的一个项目中创建了一些代码,这些代码可能会对您有所帮助,该项目也使用了摄像头 这是加速计代表的代码,您可以在其中跟踪设备的位置 - (void)accelerometer:(UIAccelerometer *)acceleromet

我正试图使用UIC加速度计在Objective-C的前后摄像头之间切换。基本上,如果设备正面朝上,我希望后面的摄像头打开。如果设备正面朝下(屏幕朝下),我希望前摄像头处于活动状态。解决这个问题的最好办法是什么?我正在通过AVFoundation访问摄像头。谢谢

我在我的一个项目中创建了一些代码,这些代码可能会对您有所帮助,该项目也使用了摄像头

这是加速计代表的代码,您可以在其中跟踪设备的位置

- (void)accelerometer:(UIAccelerometer *)accelerometer didAccelerate:(UIAcceleration *)acceleration;
{
   CGFloat x = -[acceleration x];
   CGFloat y = [acceleration y];
   CGFloat angle = atan2(y, x);

   if ( angle >= -2.25f && angle <= -0.25f )
   {
        self.interfaceOrientation = UIInterfaceOrientationPortrait;
   }
   else if ( angle >= -1.75f && angle <= 0.75f )
   {
        self.interfaceOrientation = UIInterfaceOrientationLandscapeRight;
   }
   else if( angle >= 0.75f && angle <= 2.25f )
   {
        self.interfaceOrientation = UIInterfaceOrientationPortraitUpsideDown;
   }
   else if ( angle <= -2.25f || angle >= 2.25f )
   {
        self.interfaceOrientation = UIInterfaceOrientationLandscapeLeft;
   }
}
-(无效)加速计:(UIAccelerator*)加速计DID加速度:(UIAcceleration*)加速度;
{
CGFloat x=-[加速度x];
cGy=[加速度y];
cG浮动角度=atan2(y,x);

如果(angle>=-2.25f&&angle=-1.75f&&angle=0.75f&&angle这是假设您通过UIImagePickerController使用相机,对吗?如果我通过AVFoundation创建它,过程会是什么样子?是的,它使用UIImagePickerController。嗯,我从未使用过AVFoundation,因此我无法明确说明如何将相机FRfront更改为back,但我相信你可以使用所有加速计代码。就像我做的那样,创建interfaceOrientation属性,在你的类中设置代理,启动加速计,等等,永远不要忘记在你关闭/完成查看/查看控制器后取消加速计。明白了,谢谢!你到底在哪里在前后摄像头之间切换?W嗯,在我的例子中,UIImagePickerController中有一个名为
cameraDevice
的属性,您可以将其设置为
UIImagePickerController-CameradeviceFront
UIImagePickerController-Cameradevicerar
。当您使用AVFoundation时,这会有点不同,但我认为这在google中很容易找到。