Skip to content

Ensure Scanner Always Portait #56

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Sep 13, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Example/PodApp/Podfile.lock
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
PODS:
- Sections (0.8.0)
- SplitScreenScanner (10.0.2):
- SplitScreenScanner (10.0.3):
- Sections

DEPENDENCIES:
Expand All @@ -16,7 +16,7 @@ EXTERNAL SOURCES:

SPEC CHECKSUMS:
Sections: efc268a207d0e7afba82d2a0efd6cdf61872b5d4
SplitScreenScanner: 013b34ebf4af03a51e2685a7f87051c9f2cdb6b3
SplitScreenScanner: 982b1008140faf652295c1ee5541e0f6aa002bfa

PODFILE CHECKSUM: a50e47e37e36a517f8de6ae75d836fb0fdfdecfd

Expand Down
24 changes: 21 additions & 3 deletions Sources/SplitScreenScanner/Classes/ContinuousBarcodeScanner.swift
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ final class ContinuousBarcodeScanner {
metadataOutput.setMetadataObjectsDelegate(self, queue: metadataQueue)
}

func startRunning(barcodeScannedClosure: @escaping BarcodeScannedClosure) {
func startRunning(rectOfInterest: CGRect, _ barcodeScannedClosure: @escaping BarcodeScannedClosure) {
metadataOutput.rectOfInterest = rectOfInterest
metadataOutput.metadataObjectTypes = metadataOutput.availableMetadataObjectTypes
self.barcodeScannedClosure = barcodeScannedClosure
}
Expand Down Expand Up @@ -99,7 +100,23 @@ final class ContinuousBarcodeScanner {
captureSession.addInput(videoInput)

previewLayer = AVCaptureVideoPreviewLayer(session: captureSession)
previewLayer.frame = previewView.bounds

if previewView.bounds.height > previewView.bounds.width {
previewLayer.frame = .init(
x: 0,
y: 0,
width: previewView.bounds.height,
height: previewView.bounds.width
)
} else {
previewLayer.frame = .init(
x: 0,
y: 0,
width: previewView.bounds.width,
height: previewView.bounds.height
)
}

previewLayer.videoGravity = .resizeAspectFill

metadataCapture = MetadataContinousCapture()
Expand Down Expand Up @@ -161,7 +178,8 @@ extension ContinuousBarcodeScanner {
func startRunning() {
captureSession.startRunning()

metadataCapture.startRunning { [weak self] barcodeObject in
let rectOfInterest = previewLayer.metadataOutputRectConverted(fromLayerRect: previewView.bounds)
metadataCapture.startRunning(rectOfInterest: rectOfInterest) { [weak self] barcodeObject in
self?.delegate?.didScan(barcode: barcodeObject.stringValue ?? "")
self?.addBarcodeOverlayViewFor(barcodeObject: barcodeObject)
}
Expand Down
2 changes: 1 addition & 1 deletion SplitScreenScanner.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

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

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