-
Notifications
You must be signed in to change notification settings - Fork 15
Fix UIViewController init & make it a Swift Package #11
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
Open
hermanbanken
wants to merge
2
commits into
sebromero:master
Choose a base branch
from
hermanbanken:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| // swift-tools-version: 5.6 | ||
| // The swift-tools-version declares the minimum version of Swift required to build this package. | ||
|
|
||
| import PackageDescription | ||
|
|
||
| let package = Package( | ||
| name: "QRCoder", | ||
| platforms: [.iOS(.v12)], | ||
| products: [ | ||
| // Products define the executables and libraries a package produces, and make them visible to other packages. | ||
| .library( | ||
| name: "QRCoder", | ||
| targets: ["QRCoder"] | ||
| ), | ||
| ], | ||
| dependencies: [ | ||
| // Dependencies declare other packages that this package depends on. | ||
| // .package(url: /* package url */, from: "1.0.0"), | ||
| ], | ||
| targets: [ | ||
| // Targets are the basic building blocks of a package. A target can define a module or a test suite. | ||
| // Targets can depend on other targets in this package, and on products in packages this package depends on. | ||
| .target( | ||
| name: "QRCoder", | ||
| dependencies: [], | ||
| path: "Pod/Classes"), | ||
| ] | ||
| ) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -29,10 +29,18 @@ open class QRCodeScannerViewController: UIViewController, AVCaptureMetadataOutpu | |||||
| public var showHighlightView:Bool = true | ||||||
|
|
||||||
| //MARK: Lifecycle | ||||||
|
|
||||||
| public init() { | ||||||
| super.init(nibName: nil, bundle: nil) | ||||||
| setup() | ||||||
| } | ||||||
|
|
||||||
| required public init?(coder aDecoder: NSCoder) { | ||||||
| super.init(coder: aDecoder) | ||||||
|
|
||||||
| setup() | ||||||
| } | ||||||
|
|
||||||
| private func setup() { | ||||||
| highlightView.autoresizingMask = [.flexibleTopMargin, .flexibleLeftMargin, .flexibleRightMargin, .flexibleBottomMargin] | ||||||
| highlightView.layer.borderColor = UIColor.green.cgColor | ||||||
| highlightView.layer.borderWidth = 3 | ||||||
|
|
@@ -76,7 +84,7 @@ open class QRCodeScannerViewController: UIViewController, AVCaptureMetadataOutpu | |||||
| videoPreviewLayer.frame = self.view.bounds | ||||||
| videoPreviewLayer.videoGravity = AVLayerVideoGravity.resizeAspectFill | ||||||
| view.layer.addSublayer(videoPreviewLayer) | ||||||
| view.bringSubview(toFront: highlightView) | ||||||
| view.bringSubviewToFront(highlightView) | ||||||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
| } | ||||||
|
|
||||||
| override open func viewDidAppear(_ animated: Bool) { | ||||||
|
|
@@ -86,7 +94,7 @@ open class QRCodeScannerViewController: UIViewController, AVCaptureMetadataOutpu | |||||
|
|
||||||
| override open func viewWillDisappear(_ animated: Bool) { | ||||||
| super.viewWillDisappear(animated) | ||||||
| captureSession.stopRunning() | ||||||
| stopRunning() | ||||||
| } | ||||||
|
|
||||||
| open override func viewWillTransition(to size: CGSize, with coordinator: UIViewControllerTransitionCoordinator) { | ||||||
|
|
@@ -136,7 +144,7 @@ open class QRCodeScannerViewController: UIViewController, AVCaptureMetadataOutpu | |||||
| * in subclasses to detect error. Do not dismiss controller immediately. | ||||||
| * @param error The error object | ||||||
| **/ | ||||||
| public func didFailWithError(error: NSError) { | ||||||
| open func didFailWithError(error: NSError) { | ||||||
| print("Error: \(error.description)") | ||||||
| } | ||||||
|
|
||||||
|
|
@@ -146,17 +154,28 @@ open class QRCodeScannerViewController: UIViewController, AVCaptureMetadataOutpu | |||||
| public func startQRCodeScanningSession(){ | ||||||
| updateVideoOrientation(orientation: UIApplication.shared.statusBarOrientation) | ||||||
| highlightView.frame = CGRect.zero | ||||||
| captureSession.startRunning() | ||||||
| startRunning() | ||||||
| } | ||||||
|
|
||||||
| /** | ||||||
| Stops the scanning session | ||||||
| */ | ||||||
| public func stopQRCodeScanningSession(){ | ||||||
| captureSession.stopRunning() | ||||||
| stopRunning() | ||||||
| highlightView.frame = CGRect.zero | ||||||
| } | ||||||
|
|
||||||
| private func startRunning() { | ||||||
| DispatchQueue.global(qos: .background).async { | ||||||
| self.captureSession.startRunning() | ||||||
| } | ||||||
| } | ||||||
| private func stopRunning() { | ||||||
| DispatchQueue.global(qos: .background).async { | ||||||
| self.captureSession.stopRunning() | ||||||
| } | ||||||
| } | ||||||
|
|
||||||
| //MARK: AVCaptureMetadataOutputObjectsDelegate | ||||||
|
|
||||||
| public func metadataOutput(_ output: AVCaptureMetadataOutput, didOutput metadataObjects: [AVMetadataObject], from connection: AVCaptureConnection) { | ||||||
|
|
@@ -187,7 +206,7 @@ open class QRCodeScannerViewController: UIViewController, AVCaptureMetadataOutpu | |||||
| captureSession.stopRunning() | ||||||
|
|
||||||
| if !showHighlightView && !self.processQRCodeContent(qrCodeContent: qrCode) { | ||||||
| self.captureSession.startRunning() | ||||||
| captureSession.startRunning() | ||||||
| } else { | ||||||
| DispatchQueue.main.sync { | ||||||
| self.highlightView.frame = highlightViewRect | ||||||
|
|
||||||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.