我使用AVFoundation创建视频相机UI。包含的视图控制器只能以LandscapeRight方向显示。当改变通过预览层的输出方向,它会显示正确:改变AVCaptureVideoPreviewLayer方向的问题
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;
}
SOLUTION:
这是解决双方通过应用所有建议的@ Spectravideo328的答案,通过将预览图层添加到ViewControllers视图图层,而不是displayContainer子视图。
请在下面看到更新的答案。 – Spectravideo328 2013-03-10 21:19:43