Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iPhone App - Show AVFoundation video on landscape mode

I am using the AVCam example App from Apple.

This example uses AVFoundation in order to show video on a view.

I am trying to make from the AVCam a landscape App with no luck.

When screen orientation changes the video is shown rotated on the view. Is there a way of handling this problem?

like image 802
bashan Avatar asked Dec 30 '25 02:12

bashan


1 Answers

When you create your preview layer:

captureVideoPreviewLayer.orientation = UIInterfaceOrientationLandscapeLeft;

And the methods to manage rotations:

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

That worked for me.

like image 72
Samssonart Avatar answered Dec 31 '25 15:12

Samssonart