@@ -100,7 +100,7 @@ - (void)startCapture
100100 self.captureVideoPreviewLayer = [[AVCaptureVideoPreviewLayer alloc ] initWithSession: self .session];
101101 self.captureVideoPreviewLayer .videoGravity = AVLayerVideoGravityResizeAspectFill;
102102 self.captureVideoPreviewLayer .frame = viewLayer.bounds ;
103- self.captureVideoPreviewLayer .connection .videoOrientation = (AVCaptureVideoOrientation)[[UIDevice currentDevice ] orientation ];
103+ self.captureVideoPreviewLayer .connection .videoOrientation = [ self videoOrientationForInterfaceOrientation: [[UIApplication sharedApplication ] statusBarOrientation ] ];
104104 [viewLayer addSublayer: _captureVideoPreviewLayer];
105105 });
106106 }
@@ -110,7 +110,22 @@ - (void)startCapture
110110- (void )deviceOrientationDidChange : (NSNotification *)notification
111111{
112112 if (self.captureVideoPreviewLayer .connection .supportsVideoOrientation ) {
113- self.captureVideoPreviewLayer .connection .videoOrientation = (AVCaptureVideoOrientation)[[UIDevice currentDevice ] orientation ];
113+ self.captureVideoPreviewLayer .connection .videoOrientation = [self videoOrientationForInterfaceOrientation: [[UIApplication sharedApplication ] statusBarOrientation ]];
114+ }
115+ }
116+
117+ - (AVCaptureVideoOrientation)videoOrientationForInterfaceOrientation : (UIInterfaceOrientation)orientation
118+ {
119+ switch (orientation) {
120+ case UIInterfaceOrientationPortrait:
121+ return AVCaptureVideoOrientationPortrait;
122+ case UIInterfaceOrientationPortraitUpsideDown:
123+ return AVCaptureVideoOrientationPortraitUpsideDown;
124+ case UIInterfaceOrientationLandscapeLeft:
125+ return AVCaptureVideoOrientationLandscapeLeft;
126+ case UIInterfaceOrientationLandscapeRight:
127+ return AVCaptureVideoOrientationLandscapeRight;
128+ default :return AVCaptureVideoOrientationPortrait;
114129 }
115130}
116131
0 commit comments