2013-02-11 5 views
12

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 방법 안에 넣어 이것은 오류입니다. 이 오류의 원인이 무엇인지 알 수 있습니까?

감사

답변

23

기본 카메라 방향이 UIInterfaceOrientationLeft 이상한 충분하다.

카메라 회전은 장치 회전에 따라 바뀌지 않습니다. 그들은 분리되어있다. 수동 카메라의 방향을 조정해야합니다 : 당신이에 toInterfaceOrientation를 전달하는 방법에 다음을 넣어

을 (어쩌면 당신은 그래서 위의 shouldAutorotateToInterfaceOrientation에서 호출 장치가 회전 카메라가 회전) : 당신이이

미리보기 레이어 연결 받기

AVCaptureConnection *previewLayerConnection=self.previewLayer.connection; 

if ([previewLayerConnection isVideoOrientationSupported]) 
{ 
    switch (toInterfaceOrientation) 
    { 
     case UIInterfaceOrientationPortrait: 
      [previewLayerConnection setVideoOrientation:AVCaptureVideoOrientationPortrait]; 
      break; 
     case UIInterfaceOrientationLandscapeRight: 
      [previewLayerConnection setVideoOrientation:AVCaptureVideoOrientationLandscapeRight]; //home button on right. Refer to .h not doc 
      break; 
     case UIInterfaceOrientationLandscapeLeft: 
      [previewLayerConnection setVideoOrientation:AVCaptureVideoOrientationLandscapeLeft]; //home button on left. Refer to .h not doc 
      break; 
     default: 
      [previewLayerConnection setVideoOrientation:AVCaptureVideoOrientationPortrait]; //for portrait upside down. Refer to .h not doc 
      break; 
    } 
} 
+0

이 솔루션은 저에게 적합하지 않습니다. 그것은 아무 것도하지 않습니다 ... 나는 [self.prevLayer setOrientation : [[UIDevice currentDevice] orientation]]를 사용하여 문제를 해결합니다. 그러나 setOrientation은 사용되지 않으므로 좋은 해결책은 아닙니다. 감사합니다 –

+2

@ A.Vila, 질문에 언급 한 카메라 방향 및 미리보기 레이어 방향 아닙니다. 나중에 참조 할 수 있도록 AVCaptureSession은 미리보기 레이어와 카메라 출력에 대해 2 개의 개별 연결을 만들고 두 개를 따로 회전시켜야합니다. 위의 미리보기 레이어 방향에 대한 답변을 업데이트했습니다. – Spectravideo328

+0

답변 해 주셔서 감사합니다. 나는 그것을 시도했지만 오류가 있습니다. 질문을 오류 정보로 업데이트합니다. 문제가 뭔지 알아? 고마워. –