@@ -759,7 +759,7 @@ - (void)loadView {
759759- (void )viewWillAppear : (BOOL )animated {
760760
761761 // set video orientation to what the camera sees
762- self.processor .previewLayer .connection .videoOrientation = (AVCaptureVideoOrientation) [[ UIApplication sharedApplication ] statusBarOrientation ];
762+ self.processor .previewLayer .connection .videoOrientation = [ self interfaceOrientationToVideoOrientation: [ UIApplication sharedApplication ]. statusBarOrientation];
763763
764764 // this fixes the bug when the statusbar is landscape, and the preview layer
765765 // starts up in portrait (not filling the whole view)
@@ -774,7 +774,7 @@ - (void)viewDidAppear:(BOOL)animated {
774774 previewLayer.videoGravity = AVLayerVideoGravityResizeAspectFill;
775775
776776 if ([previewLayer.connection isVideoOrientationSupported ]) {
777- [ previewLayer.connection setVideoOrientation: [[ UIApplication sharedApplication ] statusBarOrientation ] ];
777+ previewLayer.connection . videoOrientation = [ self interfaceOrientationToVideoOrientation: [ UIApplication sharedApplication ]. statusBarOrientation];
778778 }
779779
780780 [self .view.layer insertSublayer: previewLayer below: [[self .view.layer sublayers ] objectAtIndex: 0 ]];
@@ -785,6 +785,21 @@ - (void)viewDidAppear:(BOOL)animated {
785785 [super viewDidAppear: animated];
786786}
787787
788+ - (AVCaptureVideoOrientation)interfaceOrientationToVideoOrientation : (UIInterfaceOrientation)orientation {
789+ switch (orientation) {
790+ case UIInterfaceOrientationPortrait:
791+ return AVCaptureVideoOrientationPortrait;
792+ case UIInterfaceOrientationPortraitUpsideDown:
793+ return AVCaptureVideoOrientationPortraitUpsideDown;
794+ case UIInterfaceOrientationLandscapeLeft:
795+ return AVCaptureVideoOrientationLandscapeLeft;
796+ case UIInterfaceOrientationLandscapeRight:
797+ return AVCaptureVideoOrientationLandscapeRight;
798+ default :
799+ return AVCaptureVideoOrientationPortrait;
800+ }
801+ }
802+
788803// --------------------------------------------------------------------------
789804- (void )startCapturing {
790805 self.processor .capturing = YES ;
0 commit comments