IPhone App - Show AVFoundation Video in Landscape Mode

I am using Apple's AVCam sample application.

This example uses AVFoundation to show video in a view.

I am trying to make a landscape application out of AVCam without any luck.

When the screen orientation changes, the video is displayed on the screen. Is there any way to solve this problem?

+3
source share
3 answers

When creating a preview layer:

captureVideoPreviewLayer.orientation = UIInterfaceOrientationLandscapeLeft;

And rotation control methods:

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

It worked for me.

+10
source

Do you use orientation and gravity settings for the preview layer?

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

- (BOOL)shouldAutorotate;

.h.

do:

- (BOOL)shouldAutorotate {
    return NO;
}

.m

.

0

All Articles