Making the QRCodeReaderView public
This commit is contained in:
parent
5850c05d7b
commit
4539cda341
|
@ -1,5 +1,11 @@
|
|||
# Change log
|
||||
|
||||
## [Version 7.5.0](https://github.com/yannickl/QRCodeReader.swift/releases/tag/7.5.0)
|
||||
Release on 2017-08-10
|
||||
|
||||
- [REFACTORING] Makes the `QRCodeReaderView` public
|
||||
- [REFACTORING] The rotation is now managed by the `QRCodeReaderView`
|
||||
|
||||
## [Version 7.4.2](https://github.com/yannickl/QRCodeReader.swift/releases/tag/7.4.2)
|
||||
Release on 2017-05-28
|
||||
|
||||
|
|
|
@ -310,6 +310,7 @@
|
|||
TargetAttributes = {
|
||||
CE412E8819D9A1E4000F294E = {
|
||||
CreatedOnToolsVersion = 6.0.1;
|
||||
DevelopmentTeam = WNK46V33W9;
|
||||
LastSwiftMigration = 0800;
|
||||
ProvisioningStyle = Automatic;
|
||||
};
|
||||
|
@ -554,7 +555,7 @@
|
|||
ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES;
|
||||
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
|
||||
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
|
||||
DEVELOPMENT_TEAM = "";
|
||||
DEVELOPMENT_TEAM = WNK46V33W9;
|
||||
INFOPLIST_FILE = QRCodeReader.swift/Info.plist;
|
||||
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
|
||||
PRODUCT_BUNDLE_IDENTIFIER = com.workandplay.qrcodereader;
|
||||
|
@ -569,7 +570,7 @@
|
|||
ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES;
|
||||
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
|
||||
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
|
||||
DEVELOPMENT_TEAM = "";
|
||||
DEVELOPMENT_TEAM = WNK46V33W9;
|
||||
INFOPLIST_FILE = QRCodeReader.swift/Info.plist;
|
||||
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
|
||||
PRODUCT_BUNDLE_IDENTIFIER = com.workandplay.qrcodereader;
|
||||
|
|
|
@ -26,8 +26,8 @@
|
|||
|
||||
import UIKit
|
||||
|
||||
final class QRCodeReaderView: UIView, QRCodeReaderDisplayable {
|
||||
lazy var overlayView: UIView? = {
|
||||
final public class QRCodeReaderView: UIView, QRCodeReaderDisplayable {
|
||||
public lazy var overlayView: UIView? = {
|
||||
let ov = ReaderOverlayView()
|
||||
|
||||
ov.backgroundColor = .clear
|
||||
|
@ -37,7 +37,7 @@ final class QRCodeReaderView: UIView, QRCodeReaderDisplayable {
|
|||
return ov
|
||||
}()
|
||||
|
||||
let cameraView: UIView = {
|
||||
public let cameraView: UIView = {
|
||||
let cv = UIView()
|
||||
|
||||
cv.clipsToBounds = true
|
||||
|
@ -46,7 +46,7 @@ final class QRCodeReaderView: UIView, QRCodeReaderDisplayable {
|
|||
return cv
|
||||
}()
|
||||
|
||||
lazy var cancelButton: UIButton? = {
|
||||
public lazy var cancelButton: UIButton? = {
|
||||
let cb = UIButton()
|
||||
|
||||
cb.translatesAutoresizingMaskIntoConstraints = false
|
||||
|
@ -55,7 +55,7 @@ final class QRCodeReaderView: UIView, QRCodeReaderDisplayable {
|
|||
return cb
|
||||
}()
|
||||
|
||||
lazy var switchCameraButton: UIButton? = {
|
||||
public lazy var switchCameraButton: UIButton? = {
|
||||
let scb = SwitchCameraButton()
|
||||
|
||||
scb.translatesAutoresizingMaskIntoConstraints = false
|
||||
|
@ -63,7 +63,7 @@ final class QRCodeReaderView: UIView, QRCodeReaderDisplayable {
|
|||
return scb
|
||||
}()
|
||||
|
||||
lazy var toggleTorchButton: UIButton? = {
|
||||
public lazy var toggleTorchButton: UIButton? = {
|
||||
let ttb = ToggleTorchButton()
|
||||
|
||||
ttb.translatesAutoresizingMaskIntoConstraints = false
|
||||
|
@ -71,7 +71,10 @@ final class QRCodeReaderView: UIView, QRCodeReaderDisplayable {
|
|||
return ttb
|
||||
}()
|
||||
|
||||
func setupComponents(showCancelButton: Bool, showSwitchCameraButton: Bool, showTorchButton: Bool, showOverlayView: Bool) {
|
||||
private weak var reader: QRCodeReader?
|
||||
|
||||
public func setupComponents(showCancelButton: Bool, showSwitchCameraButton: Bool, showTorchButton: Bool, showOverlayView: Bool, reader: QRCodeReader?) {
|
||||
self.reader = reader
|
||||
translatesAutoresizingMaskIntoConstraints = false
|
||||
|
||||
addComponents()
|
||||
|
@ -122,6 +125,7 @@ final class QRCodeReaderView: UIView, QRCodeReaderDisplayable {
|
|||
|
||||
func addRedBorder() {
|
||||
self.startTimerForBorderReset()
|
||||
|
||||
if let ovl = self.overlayView as? ReaderOverlayView {
|
||||
ovl.overlayColor = .red
|
||||
}
|
||||
|
@ -129,14 +133,29 @@ final class QRCodeReaderView: UIView, QRCodeReaderDisplayable {
|
|||
|
||||
func addGreenBorder() {
|
||||
self.startTimerForBorderReset()
|
||||
|
||||
if let ovl = self.overlayView as? ReaderOverlayView {
|
||||
ovl.overlayColor = .green
|
||||
}
|
||||
}
|
||||
|
||||
func orientationDidChange() {
|
||||
setNeedsDisplay()
|
||||
overlayView?.setNeedsDisplay()
|
||||
|
||||
if let connection = reader?.previewLayer.connection, connection.isVideoOrientationSupported {
|
||||
let orientation = UIDevice.current.orientation
|
||||
let supportedInterfaceOrientations = UIApplication.shared.supportedInterfaceOrientations(for: nil)
|
||||
|
||||
connection.videoOrientation = QRCodeReader.videoOrientation(deviceOrientation: orientation, withSupportedOrientations: supportedInterfaceOrientations, fallbackOrientation: connection.videoOrientation)
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: - Convenience Methods
|
||||
|
||||
private func addComponents() {
|
||||
NotificationCenter.default.addObserver(self, selector: #selector(QRCodeReaderView.orientationDidChange), name: .UIDeviceOrientationDidChange, object: nil)
|
||||
|
||||
addSubview(cameraView)
|
||||
|
||||
if let ov = overlayView {
|
||||
|
|
|
@ -49,8 +49,10 @@ public protocol QRCodeReaderDisplayable {
|
|||
- Parameter showCancelButton: Flag to know whether you should display the cancel button.
|
||||
- Parameter showSwitchCameraButton: Flag to know whether you should display the switch camera button.
|
||||
- Parameter showTorchButton: Flag to know whether you should display the toggle torch button.
|
||||
- Parameter showOverlayView: Flag to know whether you should display the overlay.
|
||||
- Parameter reader: A reference to the code reader.
|
||||
*/
|
||||
func setupComponents(showCancelButton: Bool, showSwitchCameraButton: Bool, showTorchButton: Bool, showOverlayView: Bool)
|
||||
func setupComponents(showCancelButton: Bool, showSwitchCameraButton: Bool, showTorchButton: Bool, showOverlayView: Bool, reader: QRCodeReader?)
|
||||
}
|
||||
|
||||
/// The `QRCodeReaderContainer` structure embed the view displayed by the controller. The embeded view must be conform to the `QRCodeReaderDisplayable` protocol.
|
||||
|
@ -70,7 +72,7 @@ public struct QRCodeReaderContainer {
|
|||
|
||||
// MARK: - Convenience Methods
|
||||
|
||||
func setupComponents(showCancelButton: Bool, showSwitchCameraButton: Bool, showTorchButton: Bool, showOverlayView: Bool) {
|
||||
displayable.setupComponents(showCancelButton: showCancelButton, showSwitchCameraButton: showSwitchCameraButton, showTorchButton: showTorchButton, showOverlayView: showOverlayView)
|
||||
func setupComponents(showCancelButton: Bool, showSwitchCameraButton: Bool, showTorchButton: Bool, showOverlayView: Bool, reader: QRCodeReader? = nil) {
|
||||
displayable.setupComponents(showCancelButton: showCancelButton, showSwitchCameraButton: showSwitchCameraButton, showTorchButton: showTorchButton, showOverlayView: showOverlayView, reader: reader)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -38,7 +38,6 @@ public class QRCodeReaderViewController: UIViewController {
|
|||
let showSwitchCameraButton: Bool
|
||||
let showTorchButton: Bool
|
||||
let showOverlayView: Bool
|
||||
let handleOrientationChange: Bool
|
||||
|
||||
// MARK: - Managing the Callback Responders
|
||||
|
||||
|
@ -69,7 +68,6 @@ public class QRCodeReaderViewController: UIViewController {
|
|||
showSwitchCameraButton = builder.showSwitchCameraButton
|
||||
showTorchButton = builder.showTorchButton
|
||||
showOverlayView = builder.showOverlayView
|
||||
handleOrientationChange = builder.handleOrientationChange
|
||||
|
||||
super.init(nibName: nil, bundle: nil)
|
||||
|
||||
|
@ -94,8 +92,6 @@ public class QRCodeReaderViewController: UIViewController {
|
|||
}
|
||||
|
||||
setupUIComponentsWithCancelButtonTitle(builder.cancelButtonTitle)
|
||||
|
||||
NotificationCenter.default.addObserver(self, selector: #selector(orientationDidChange), name: NSNotification.Name.UIDeviceOrientationDidChange, object: nil)
|
||||
}
|
||||
|
||||
required public init?(coder aDecoder: NSCoder) {
|
||||
|
@ -106,15 +102,11 @@ public class QRCodeReaderViewController: UIViewController {
|
|||
showTorchButton = false
|
||||
showSwitchCameraButton = false
|
||||
showOverlayView = false
|
||||
handleOrientationChange = false
|
||||
|
||||
super.init(coder: aDecoder)
|
||||
}
|
||||
|
||||
// MARK: - Responding to View Events
|
||||
override public var supportedInterfaceOrientations: UIInterfaceOrientationMask {
|
||||
return parent?.supportedInterfaceOrientations ?? .all
|
||||
}
|
||||
|
||||
override public func viewWillAppear(_ animated: Bool) {
|
||||
super.viewWillAppear(animated)
|
||||
|
@ -136,20 +128,6 @@ public class QRCodeReaderViewController: UIViewController {
|
|||
codeReader.previewLayer.frame = view.bounds
|
||||
}
|
||||
|
||||
// MARK: - Managing the Orientation
|
||||
|
||||
func orientationDidChange(_ notification: Notification) {
|
||||
readerView.view.setNeedsDisplay()
|
||||
|
||||
if showOverlayView, let qrv = readerView.displayable as? QRCodeReaderView {
|
||||
qrv.overlayView?.setNeedsDisplay()
|
||||
}
|
||||
|
||||
if handleOrientationChange == true, let device = notification.object as? UIDevice, let connection = codeReader.previewLayer.connection, connection.isVideoOrientationSupported {
|
||||
connection.videoOrientation = QRCodeReader.videoOrientation(deviceOrientation: device.orientation, withSupportedOrientations: supportedInterfaceOrientations, fallbackOrientation: connection.videoOrientation)
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: - Initializing the AV Components
|
||||
|
||||
private func setupUIComponentsWithCancelButtonTitle(_ cancelButtonTitle: String) {
|
||||
|
@ -158,7 +136,7 @@ public class QRCodeReaderViewController: UIViewController {
|
|||
let sscb = showSwitchCameraButton && codeReader.hasFrontDevice
|
||||
let stb = showTorchButton && codeReader.isTorchAvailable
|
||||
|
||||
readerView.setupComponents(showCancelButton: showCancelButton, showSwitchCameraButton: sscb, showTorchButton: stb, showOverlayView: showOverlayView)
|
||||
readerView.setupComponents(showCancelButton: showCancelButton, showSwitchCameraButton: sscb, showTorchButton: stb, showOverlayView: showOverlayView, reader: codeReader)
|
||||
|
||||
// Setup action methods
|
||||
|
||||
|
|
Loading…
Reference in New Issue