iPhone App - Show AVFoundation video on landscape mode

若如初见. 提交于 2019-12-06 03:05:21
Samssonart

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.

Are you using the 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;
Jeff Stone

Declare

- (BOOL)shouldAutorotate;

in your .h .

Then do:

- (BOOL)shouldAutorotate {
    return NO;
}

in your .m

This will force it to not rotate.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!