@@ -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 = [self videoOrientationForDeviceOrientation : [[UIDevice currentDevice ] orientation ]];
103+ self.captureVideoPreviewLayer .connection .videoOrientation = [self videoOrientationForInterfaceOrientation : [[UIApplication sharedApplication ] statusBarOrientation ]];
104104 [viewLayer addSublayer: _captureVideoPreviewLayer];
105105 });
106106 }
@@ -110,17 +110,23 @@ - (void)startCapture
110110- (void )deviceOrientationDidChange : (NSNotification *)notification
111111{
112112 if (self.captureVideoPreviewLayer .connection .supportsVideoOrientation ) {
113- self.captureVideoPreviewLayer .connection .videoOrientation = [self videoOrientationForDeviceOrientation : [[UIDevice currentDevice ] orientation ]];
113+ self.captureVideoPreviewLayer .connection .videoOrientation = [self videoOrientationForInterfaceOrientation : [[UIApplication sharedApplication ] statusBarOrientation ]];
114114 }
115115}
116116
117- - (AVCaptureVideoOrientation)videoOrientationForDeviceOrientation : (UIDeviceOrientation )orientation
117+ - (AVCaptureVideoOrientation)videoOrientationForInterfaceOrientation : (UIInterfaceOrientation )orientation
118118{
119- if (orientation == UIDeviceOrientationFaceUp || orientation == UIDeviceOrientationFaceDown) {
120- return AVCaptureVideoOrientationPortrait;
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;
121129 }
122-
123- return (AVCaptureVideoOrientation)orientation;
124130}
125131
126132- (BOOL )isAccessibilityElement
0 commit comments