Skip to content

Commit 27da626

Browse files
authored
Merge pull request #56 from clutter/scanner-fix
Ensure Scanner Always Portait
2 parents f9f2764 + fce746d commit 27da626

File tree

3 files changed

+24
-6
lines changed

3 files changed

+24
-6
lines changed

Example/PodApp/Podfile.lock

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
PODS:
22
- Sections (0.8.0)
3-
- SplitScreenScanner (10.0.2):
3+
- SplitScreenScanner (10.0.3):
44
- Sections
55

66
DEPENDENCIES:
@@ -16,7 +16,7 @@ EXTERNAL SOURCES:
1616

1717
SPEC CHECKSUMS:
1818
Sections: efc268a207d0e7afba82d2a0efd6cdf61872b5d4
19-
SplitScreenScanner: 013b34ebf4af03a51e2685a7f87051c9f2cdb6b3
19+
SplitScreenScanner: 982b1008140faf652295c1ee5541e0f6aa002bfa
2020

2121
PODFILE CHECKSUM: a50e47e37e36a517f8de6ae75d836fb0fdfdecfd
2222

Sources/SplitScreenScanner/Classes/ContinuousBarcodeScanner.swift

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,8 @@ final class ContinuousBarcodeScanner {
3535
metadataOutput.setMetadataObjectsDelegate(self, queue: metadataQueue)
3636
}
3737

38-
func startRunning(barcodeScannedClosure: @escaping BarcodeScannedClosure) {
38+
func startRunning(rectOfInterest: CGRect, _ barcodeScannedClosure: @escaping BarcodeScannedClosure) {
39+
metadataOutput.rectOfInterest = rectOfInterest
3940
metadataOutput.metadataObjectTypes = metadataOutput.availableMetadataObjectTypes
4041
self.barcodeScannedClosure = barcodeScannedClosure
4142
}
@@ -99,7 +100,23 @@ final class ContinuousBarcodeScanner {
99100
captureSession.addInput(videoInput)
100101

101102
previewLayer = AVCaptureVideoPreviewLayer(session: captureSession)
102-
previewLayer.frame = previewView.bounds
103+
104+
if previewView.bounds.height > previewView.bounds.width {
105+
previewLayer.frame = .init(
106+
x: 0,
107+
y: 0,
108+
width: previewView.bounds.height,
109+
height: previewView.bounds.width
110+
)
111+
} else {
112+
previewLayer.frame = .init(
113+
x: 0,
114+
y: 0,
115+
width: previewView.bounds.width,
116+
height: previewView.bounds.height
117+
)
118+
}
119+
103120
previewLayer.videoGravity = .resizeAspectFill
104121

105122
metadataCapture = MetadataContinousCapture()
@@ -161,7 +178,8 @@ extension ContinuousBarcodeScanner {
161178
func startRunning() {
162179
captureSession.startRunning()
163180

164-
metadataCapture.startRunning { [weak self] barcodeObject in
181+
let rectOfInterest = previewLayer.metadataOutputRectConverted(fromLayerRect: previewView.bounds)
182+
metadataCapture.startRunning(rectOfInterest: rectOfInterest) { [weak self] barcodeObject in
165183
self?.delegate?.didScan(barcode: barcodeObject.stringValue ?? "")
166184
self?.addBarcodeOverlayViewFor(barcodeObject: barcodeObject)
167185
}

SplitScreenScanner.podspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
Pod::Spec.new do |s|
1010
s.name = 'SplitScreenScanner'
11-
s.version = '10.0.2'
11+
s.version = '10.0.3'
1212
s.summary = 'Swift library for scanning barcodes with half the screen devoted to scan history'
1313

1414
# This description is used to generate tags and improve search results.

0 commit comments

Comments
 (0)