【发布时间】:2013-02-25 09:20:10
【问题描述】:
我正在使用 AVFoundation 创建摄像机 UI。包含的视图控制器将仅以 LandscapeRight 方向显示。通过预览层改变输出方向时,正确显示:
self.previewLayer = [[AVCaptureVideoPreviewLayer alloc] initWithSession:self.captureSession];
self.previewLayer.orientation = AVCaptureVideoOrientationLandscapeRight;
[self.displayContainer.layer addSublayer:self.previewLayer];
但是,我意识到 AVCaptureVideoPreviewLayer 的方向属性已被弃用,取而代之的是 AVCaptureConnection.videoOrientation。当使用它时:
self.previewLayer.connection.videoOrientation = AVCaptureVideoOrientationLandscapeRight;
预览层似乎根本没有改变方向,即使在尝试不同的方向选项时也是如此。为了按照推荐的方式执行此操作,我是否还缺少另一个步骤?
编辑:
以下是视图控制器中的自动旋转方法:
-(BOOL)shouldAutorotate
{
return NO;
}
-(NSUInteger)supportedInterfaceOrientations
{
return UIInterfaceOrientationMaskLandscapeRight;
}
-(UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
return UIInterfaceOrientationLandscapeRight;
}
解决方案:
通过应用@Spectravideo328 答案中的所有建议以及将预览层添加到 ViewControllers 视图层(而不是 displayContainer 子视图)来解决此问题。
【问题讨论】:
-
请参阅下面的更新答案。
标签: ios6 avfoundation calayer avcapturesession autorotate