2013-03-15 2 views
2

최신 SDK가 포함 된 iOS 앱을 개발하고 있습니다.UIInterfaceOrientation은 Landscape이지만 UIView는 Portrait 모드입니다.

저는 LandscapeRight 방향 만 지원하는 카메라 앱을 개발하고 있습니다.

메인 주 ViewControllerAVCaptureVideoPreviewLayerUIView을 추가했습니다. 다른 말로하면, 주 ViewController 주보기가 있고 videoPreviewView이라는 또 다른보기가 AVCaptureVideoPreviewLayer입니다.

BOUNDS: {{0, 0}, {320, 480}} 

그러나 UIInterfaceOrientationUIInterfaceOrientationLandscapeRight하고 그 방향을 함께 내가 이러한 값을 얻을 것입니다 :

BOUNDS: {{0, 0}, {480, 320}} 
을 나는이 로그를 얻을

- (void) viewWillAppear:(BOOL)animated 
{ 
    [super viewWillAppear:animated]; 
    [self setUpVideo]; 
} 

- (void)setUpVideo 
{ 
    NSLog(@"Set up video"); 
    if (DataExchanger.cameraManager != nil) 
    { 
     UIView *view = [self videoPreviewView]; 
     CALayer *viewLayer = [view layer]; 
     [viewLayer setMasksToBounds:YES]; 

     AVCaptureVideoPreviewLayer *newCaptureVideoPreviewLayer = [[AVCaptureVideoPreviewLayer alloc] initWithSession:DataExchanger.cameraManager.captureSession]; 
     CGRect bounds = [view bounds]; 
     NSLog(@"BOUNDS: %@", NSStringFromCGRect(bounds)); 

     [newCaptureVideoPreviewLayer setFrame:bounds]; 
     [newCaptureVideoPreviewLayer setVideoGravity:AVLayerVideoGravityResizeAspectFill]; 

     [viewLayer insertSublayer:newCaptureVideoPreviewLayer below:[[viewLayer sublayers] objectAtIndex:0]]; 
    } 
} 

:

나는 viewWillAppear: 방법에 AVCaptureVideoPreviewLayer을 설정

또 다른 문제는 나는 비디오를 -90도으로 돌렸다.

이 결과는 stackoverflow question이지만, - (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation 메서드는 실행되지 않습니다.

무슨 일입니까? 이 문제를 어떻게 해결할 수 있습니까?

답변

-1
  1. 기본 AVCaptureVideoPreviewLayer 객체 방향은 가로입니다!
  2. AVCaptureVideoPreviewLayer의 방향은 장치 방향에 따라 바뀌지 않습니다. 수동으로 변경해야합니다.

iOS6의 :

AVCaptureConnection *previewLayerConnection=self.newCaptureVideoPreviewLayer.connection; 
if ([previewLayerConnection isVideoOrientationSupported]) 
    [previewLayerConnection setVideoOrientation:AVCaptureVideoOrientationLandscapeRight]; 

< iOS6의 :

  • 는 미리보기 층의 연결을 호출해야하고 회전 수동으로 변경하려면 내가 일하고 있어요

    if ([self.newCaptureVideoPreviewLayer isOrientationSupported]) 
    [self.newCaptureVideoPreviewLayer setOrientation:AVCaptureVideoOrientationLandscapeRight]; 
    
  • +0

    최신 SDK와 iOS 5.0 이상을 지원합니다. 어떤 버전의 대답을 사용해야합니까? 하지만 이제는 두 번째 옵션을 사용하고 있으며이 문제가 발생하여 내 대답이 내 문제를 해결하지 못했다고 생각합니다. – VansFannel

    +0

    누군가가 내 답변 3 개를 임의로, 게시 후 3 개월 동안 downvote한다면; 이유가있는 경우 의견을 게시하십시오 (있는 경우). – Spectravideo328