From 26f07b01c41816dcba6becf2fefe69538ec73eda Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Valentin=20H=C4=83loiu?= Date: Tue, 27 Nov 2018 19:29:11 +0100 Subject: [PATCH] Convert interface orientation to video orientation on iOS (#719) * Add missing framework declarations for iOS * Convert interface orientation to video orientation on iOS --- plugin.xml | 5 ++++- src/ios/CDVBarcodeScanner.mm | 19 +++++++++++++++++-- 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/plugin.xml b/plugin.xml index 71c1de88..662daba8 100644 --- a/plugin.xml +++ b/plugin.xml @@ -21,6 +21,9 @@ + + + @@ -68,4 +71,4 @@ - \ No newline at end of file + diff --git a/src/ios/CDVBarcodeScanner.mm b/src/ios/CDVBarcodeScanner.mm index c59bcbe2..91f183a1 100644 --- a/src/ios/CDVBarcodeScanner.mm +++ b/src/ios/CDVBarcodeScanner.mm @@ -759,7 +759,7 @@ - (void)loadView { - (void)viewWillAppear:(BOOL)animated { // set video orientation to what the camera sees - self.processor.previewLayer.connection.videoOrientation = (AVCaptureVideoOrientation) [[UIApplication sharedApplication] statusBarOrientation]; + self.processor.previewLayer.connection.videoOrientation = [self interfaceOrientationToVideoOrientation:[UIApplication sharedApplication].statusBarOrientation]; // this fixes the bug when the statusbar is landscape, and the preview layer // starts up in portrait (not filling the whole view) @@ -774,7 +774,7 @@ - (void)viewDidAppear:(BOOL)animated { previewLayer.videoGravity = AVLayerVideoGravityResizeAspectFill; if ([previewLayer.connection isVideoOrientationSupported]) { - [previewLayer.connection setVideoOrientation:[[UIApplication sharedApplication] statusBarOrientation]]; + previewLayer.connection.videoOrientation = [self interfaceOrientationToVideoOrientation:[UIApplication sharedApplication].statusBarOrientation]; } [self.view.layer insertSublayer:previewLayer below:[[self.view.layer sublayers] objectAtIndex:0]]; @@ -785,6 +785,21 @@ - (void)viewDidAppear:(BOOL)animated { [super viewDidAppear:animated]; } +- (AVCaptureVideoOrientation)interfaceOrientationToVideoOrientation:(UIInterfaceOrientation)orientation { + switch (orientation) { + case UIInterfaceOrientationPortrait: + return AVCaptureVideoOrientationPortrait; + case UIInterfaceOrientationPortraitUpsideDown: + return AVCaptureVideoOrientationPortraitUpsideDown; + case UIInterfaceOrientationLandscapeLeft: + return AVCaptureVideoOrientationLandscapeLeft; + case UIInterfaceOrientationLandscapeRight: + return AVCaptureVideoOrientationLandscapeRight; + default: + return AVCaptureVideoOrientationPortrait; + } +} + //-------------------------------------------------------------------------- - (void)startCapturing { self.processor.capturing = YES;