Skip to content
This repository was archived by the owner on Aug 11, 2020. It is now read-only.

Commit 26f07b0

Browse files
viallyjcesarmobile
authored andcommitted
Convert interface orientation to video orientation on iOS (#719)
* Add missing framework declarations for iOS * Convert interface orientation to video orientation on iOS
1 parent 9c200e0 commit 26f07b0

File tree

2 files changed

+21
-3
lines changed

2 files changed

+21
-3
lines changed

plugin.xml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@
2121
<resource-file src="src/ios/scannerOverlay.xib"/>
2222
<resource-file src="src/ios/CDVBarcodeScanner.bundle"/>
2323
<source-file src="src/ios/CDVBarcodeScanner.mm"/>
24+
<!-- frameworks -->
25+
<framework src="AVFoundation.framework" />
26+
<framework src="AudioToolbox.framework" />
2427
</platform>
2528
<platform name="android">
2629
<source-file src="src/android/com/phonegap/plugins/barcodescanner/BarcodeScanner.java" target-dir="src/com/phonegap/plugins/barcodescanner"/>
@@ -68,4 +71,4 @@
6871
<runs/>
6972
</js-module>
7073
</platform>
71-
</plugin>
74+
</plugin>

src/ios/CDVBarcodeScanner.mm

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)