我想使用AVCaptureSession使用相機捕捉圖像。iOS:相機方向
它工作正常,我啓動相機,我可以得到輸出。但是,當我旋轉設備時,我在視頻方向上遇到了一些問題。
首先,我想支持橫向左右方向,並且可能過於晚於肖像模式。
我實現:
- (BOOL) shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation) interfaceOrientation{
return UIInterfaceOrientationIsLandscapse(interfaceOrientation);
}
當我旋轉設備,它從橫向左向右橫向或反之旋轉的應用程序,但我只看到正確的攝像頭,當我在左邊的景觀。當應用處於右側橫向時,視頻旋轉180度。
非常感謝。
更新:
我試過Spectravideo328的答案,但我有一個錯誤,當我嘗試旋轉設備和應用程序崩潰。這是錯誤:
[AVCaptureVideoPreviewLayer connection]: unrecognized selector sent to instance 0xf678210
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[AVCaptureVideoPreviewLayer connection]: unrecognized selector sent to instance 0xf678210'
在此行中出現的錯誤:
AVCaptureConnection *previewLayerConnection=self.previewLayer.connection;
我把它shouldAutorotateToInterfaceOrientation方法內。 你知道這個錯誤的原因是什麼?
感謝
此解決方案對我無效。它沒有做任何事情......我使用[self.prevLayer setOrientation:[[UIDevice currentDevice] orientation]]解決了這個問題。但setOrientation已被棄用,所以它不是一個好的解決方案。謝謝 – 2013-02-13 17:41:29
@ A.Vila,你在問題中提到了相機的方向,而不是預覽層的方向。僅供將來參考,AVCaptureSession會創建2個單獨的連接(用於預覽圖層和攝像機輸出),您將不得不單獨旋轉!我更新了我上面預覽圖層方向的答案。 – Spectravideo328 2013-02-13 18:05:38
感謝您的回答。我試過了,但是我有一個錯誤。我更新錯誤信息的問題。你知道問題是什麼嗎?非常感謝。 – 2013-05-09 16:20:43