Updating the initialisation workflow
This commit is contained in:
parent
ae18697bb5
commit
ea7ffb0b32
|
@ -28,11 +28,15 @@ import AVFoundation
|
||||||
import UIKit
|
import UIKit
|
||||||
|
|
||||||
class ViewController: UIViewController, QRCodeReaderViewControllerDelegate {
|
class ViewController: UIViewController, QRCodeReaderViewControllerDelegate {
|
||||||
@IBOutlet weak var previewView: QRCodeReaderView!
|
@IBOutlet weak var previewView: QRCodeReaderView! {
|
||||||
|
didSet {
|
||||||
|
previewView.setupComponents(showCancelButton: false, showSwitchCameraButton: false, showTorchButton: false, showOverlayView: true, reader: reader)
|
||||||
|
}
|
||||||
|
}
|
||||||
lazy var reader: QRCodeReader = QRCodeReader()
|
lazy var reader: QRCodeReader = QRCodeReader()
|
||||||
lazy var readerVC: QRCodeReaderViewController = {
|
lazy var readerVC: QRCodeReaderViewController = {
|
||||||
let builder = QRCodeReaderViewControllerBuilder {
|
let builder = QRCodeReaderViewControllerBuilder {
|
||||||
$0.reader = QRCodeReader(metadataObjectTypes: [AVMetadataObject.ObjectType.qr], captureDevicePosition: .back)
|
$0.reader = QRCodeReader(metadataObjectTypes: [.qr], captureDevicePosition: .back)
|
||||||
$0.showTorchButton = true
|
$0.showTorchButton = true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -89,17 +93,11 @@ class ViewController: UIViewController, QRCodeReaderViewControllerDelegate {
|
||||||
@IBAction func scanInPreviewAction(_ sender: Any) {
|
@IBAction func scanInPreviewAction(_ sender: Any) {
|
||||||
guard checkScanPermissions(), !reader.isRunning else { return }
|
guard checkScanPermissions(), !reader.isRunning else { return }
|
||||||
|
|
||||||
previewView.setupComponents(showCancelButton: false, showSwitchCameraButton: false, showTorchButton: false, showOverlayView: true, reader: reader)
|
reader.didFindCode = { result in
|
||||||
|
print("Completion with result: \(result.value) of type \(result.metadataType)")
|
||||||
|
}
|
||||||
|
|
||||||
reader.startScanning()
|
reader.startScanning()
|
||||||
reader.didFindCode = { result in
|
|
||||||
let alert = UIAlertController(
|
|
||||||
title: "QRCodeReader",
|
|
||||||
message: String (format:"%@ (of type %@)", result.value, result.metadataType),
|
|
||||||
preferredStyle: .alert
|
|
||||||
)
|
|
||||||
alert.addAction(UIAlertAction(title: "OK", style: .cancel, handler: nil))
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// MARK: - QRCodeReader Delegate Methods
|
// MARK: - QRCodeReader Delegate Methods
|
||||||
|
|
|
@ -115,7 +115,7 @@ final public class QRCodeReaderView: UIView, QRCodeReaderDisplayable {
|
||||||
public override func layoutSubviews() {
|
public override func layoutSubviews() {
|
||||||
super.layoutSubviews()
|
super.layoutSubviews()
|
||||||
|
|
||||||
reader?.previewLayer.frame = CGRect(x: 0, y: 0, width: bounds.width, height: bounds.height)
|
reader?.previewLayer.frame = bounds
|
||||||
}
|
}
|
||||||
|
|
||||||
// MARK: - Scan Result Indication
|
// MARK: - Scan Result Indication
|
||||||
|
|
|
@ -59,6 +59,7 @@ public final class ReaderOverlayView: UIView {
|
||||||
var overlayColor: UIColor = UIColor.white {
|
var overlayColor: UIColor = UIColor.white {
|
||||||
didSet {
|
didSet {
|
||||||
self.overlay.strokeColor = overlayColor.cgColor
|
self.overlay.strokeColor = overlayColor.cgColor
|
||||||
|
|
||||||
self.setNeedsDisplay()
|
self.setNeedsDisplay()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -76,8 +77,6 @@ public final class ReaderOverlayView: UIView {
|
||||||
innerRect.size.height = minSize
|
innerRect.size.height = minSize
|
||||||
}
|
}
|
||||||
|
|
||||||
let offsetRect = innerRect.offsetBy(dx: 0, dy: 15)
|
overlay.path = UIBezierPath(roundedRect: innerRect, cornerRadius: 5).cgPath
|
||||||
|
|
||||||
overlay.path = UIBezierPath(roundedRect: offsetRect, cornerRadius: 5).cgPath
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue