iPhone App - Показать видео AVFoundation в ландшафтном режиме - PullRequest
3 голосов
/ 09 июня 2011

Я использую пример приложения AVCam от Apple.

В этом примере используется AVFoundation для отображения видео в представлении.

Я пытаюсь сделать из AVCam ландшафтное приложение без удачи.

При изменении ориентации экрана видео отображается повернутым на виде. Есть ли способ решить эту проблему?

Ответы [ 3 ]

10 голосов
/ 11 июля 2011

Когда вы создаете слой предварительного просмотра:

captureVideoPreviewLayer.orientation = UIInterfaceOrientationLandscapeLeft;

И методы управления вращениями:

-(void)willAnimateRotationToInterfaceOrientation:
        (UIInterfaceOrientation)toInterfaceOrientation 
        duration:(NSTimeInterval)duration {

  [CATransaction begin];
  if (toInterfaceOrientation==UIInterfaceOrientationLandscapeLeft){
    captureVideoPreviewLayer.orientation = UIInterfaceOrientationLandscapeLeft;
  } else {        
    captureVideoPreviewLayer.orientation = UIInterfaceOrientationLandscapeLeft;
  }

 [CATransaction commit];
 [super willAnimateRotationToInterfaceOrientation:toInterfaceOrientation duration:duration];
}

-(BOOL)shouldAutorotateToInterfaceOrientation:
        (UIInterfaceOrientation)interfaceOrientation {

  [[UIApplication sharedApplication] setStatusBarOrientation:UIInterfaceOrientationLandscapeLeft animated:NO];

  return (interfaceOrientation == UIInterfaceOrientationLandscapeLeft);
}

Это сработало для меня.

0 голосов
/ 11 октября 2012

Declare

- (BOOL)shouldAutorotate;

в вашем .ч.

Затем выполните:

- (BOOL)shouldAutorotate {
    return NO;
}

в вашем .m

Это заставит его не вращаться.

0 голосов
/ 12 июня 2011

Используете ли вы параметры ориентации и гравитации для слоя предварительного просмотра?

previewLayer = [AVCaptureVideoPreviewLayer layerWithSession:session];
previewLayer.frame = CGRectMake(0, 0, 480, 300); 
previewLayer.videoGravity = AVLayerVideoGravityResizeAspectFill;
previewLayer.orientation =  AVCaptureVideoOrientationLandscapeRight;
previewLayer.automaticallyAdjustsMirroring = YES;
...