Приложение для iPhone — показ видео AVFoundation в ландшафтном режиме

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

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

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

Когда ориентация экрана меняется, видео отображается повернутым на экране. Есть ли способ справиться с этой проблемой?


person bashan    schedule 08.06.2011    source источник


Ответы (3)


При создании слоя предварительного просмотра:

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);
}

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

person Samssonart    schedule 11.07.2011
comment
Примечание. Вам потребуется установить свойство videoOrientation для соединения, поскольку свойство ориентации устарело. - person Senseful; 05.03.2014

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

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

Объявить

- (BOOL)shouldAutorotate;

в вашем .h .

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

- (BOOL)shouldAutorotate {
    return NO;
}

в твоём м

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

person Jeff Stone    schedule 11.10.2012