1

我正在尝试制作一个显示相机预览的应用程序,并在按下按钮时单击图像。

我想在设备旋转时旋转预览,所以我正在使用

直到现在我都在使用previewlayer.orientation = toInterfaceorientationwillAutoRotateToInterfaceOrientation方法。但是现在当我在 iOS6 上运行我的应用程序时,我收到一个警告,setOrientation即现在不推荐使用预览层的方法。

另外,我认为现在这只是为了“查看”预览,图像的实际方向不会改变,无论我的“连接”视频方向是什么,它都会保持不变!

所以,建议使用setVideoOrientationAVCaptureConnection 的方法。我正在尝试使用它,但我不知道该怎么做。我想支持左右横向(以后也可能是纵向模式)。

所以我写在willAutoRotateToInterfaceOrientation

  `if([connection isVideoOrientationSupported])  
    {  
        if(toInterfaceorientation == UIInterfaceOrientationLandscapeLeft)  
        {  
           [connection setVideoorientation:AVCaptureConnectionVideoOrientationLandscapeRight];  
        }    
if(toInterfaceorientation == UIInterfaceOrientationLandscapeRight)  
        {  
           [connection setVideoorientation:AVCaptureConnectionVideoOrientationLandscapeLeft];  
        }  
    }`

但这并没有真正起作用,在 LandscapeRight 的情况下它可以正常工作,但在 LandscapeLeft 的情况下它会旋转 180 度。

我检查了该willAutoRotateToInterfaceOrientation方法正在被调用,并且块内的语句正在执行(通过设置断点),尽管结果方向好像这个方法是空的!

我希望这也会改变图像的实际方向。

4

0 回答 0