我使用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