我正在尝试创建一个显示相机预览的应用,并在按下按钮时单击图像。
我想在设备旋转时旋转预览,所以我正在使用
直到现在我在previewlayer.orientation = toInterfaceorientation
方法中使用了willAutoRotateToInterfaceOrientation
。但是现在当我在iOS6上运行我的应用程序时,我收到一条警告,即setOrientation
预览图层方法现已弃用。
此外,我认为现在只是“查看”预览,图像的实际方向不会改变,它将保持为“连接”的视频方向!
因此,建议使用AVCaptureConnection的setVideoOrientation
方法。我正在尝试使用它,但我不知道该怎么做..我想左右支持横向(也可能是后期的肖像模式)。
所以我写在willAutoRotateToInterfaceOrientation
`if([connection isVideoOrientationSupported])
{
if(toInterfaceorientation == UIInterfaceOrientationLandscapeLeft)
{
[connection setVideoorientation:AVCaptureConnectionVideoOrientationLandscapeRight];
}
if(toInterfaceorientation == UIInterfaceOrientationLandscapeRight)
{
[connection setVideoorientation:AVCaptureConnectionVideoOrientationLandscapeLeft];
}
}`
但是这不起作用,它在LandscapeRight的情况下工作正常,但在LandscapeLeft的情况下,它旋转180度。
我已经检查过正在调用willAutoRotateToInterfaceOrientation
方法,并且正在执行块内的语句(通过设置断点),尽管结果方向就像这个方法是空的一样!
我希望这也会改变图像的实际方向。