Commit e39a6907 by Sarkizz

调整扫码界面

parent 42a6a49b
......@@ -21,9 +21,6 @@ public final class MRScanningLineView: UIView {
}
}
// 2端透明比例
private let opacityRatio: Float = 0.25
private let gradientLayer = CAGradientLayer()
public override init(frame: CGRect) {
......@@ -39,9 +36,11 @@ public final class MRScanningLineView: UIView {
extension MRScanningLineView {
private func setupGradientLayer() {
gradientLayer.frame = layer.bounds
gradientLayer.config(colors: [.init(color: .clear, location: 0),
.init(color: color, location: 1-2*opacityRatio),
.init(color: .clear, location: 1)],
gradientLayer.config(colors: [.init(color: color.withAlphaComponent(0), location: 0),
.init(color: color.withAlphaComponent(0.3), location: 0.1),
.init(color: color, location: 0.5),
.init(color: color.withAlphaComponent(0.3), location: 0.9),
.init(color: color.withAlphaComponent(0), location: 1)],
direction: .horizontal(1))
layer.addSublayer(gradientLayer)
}
......
......@@ -32,6 +32,7 @@ private let innerRectViewTag = 99033
private let lineViewTag = 99034
private var managerStoreKey = "MRScanningProtocolManager"
private var privateInterfaceTypeKey = "MRScanInterfaceType"
public protocol MRScanningProtocol: NSObject {
typealias InterfaceSetting = (_ shadowView: MRScanningShadowView, _ innerView: MRScanningRectLineView,_ scanLineView: MRScanningLineView) -> Void
......@@ -60,6 +61,10 @@ extension MRScanningProtocol where Self: UIViewController {
public var scanLineView: MRScanningLineView? {
return view.viewWithTag(lineViewTag) as? MRScanningLineView
}
public var currentInterfaceTypeConfig: (scanningRect: CGRect, innerRect: CGRect)? {
return objc_getAssociatedObject(self, &privateInterfaceTypeKey) as? (scanningRect: CGRect, innerRect: CGRect)
}
}
extension MRScanningProtocol where Self: UIViewController {
......@@ -81,6 +86,7 @@ extension MRScanningProtocol where Self: UIViewController {
public func layoutScanningInterface(_ type: ScanningInterfaceType, in rect: CGRect) {
let config = type.config(in: rect)
setInterfaceTypeConfig(config)
shadowView?.frame = CGRect(origin: CGPoint.zero, size: rect.size)
shadowView?.interestFrame = config.innerRect
rectLineView?.frame = config.innerRect
......@@ -96,8 +102,8 @@ extension MRScanningProtocol where Self: UIViewController {
}
public func startScanningAnimation() {
if let lineView = scanLineView,
let rectHeight = rectLineView?.frame.height, let cornerHeight = rectLineView?.cornerLineWidth {
if let lineView = scanLineView, let rectHeight = currentInterfaceTypeConfig?.innerRect.height,
let cornerHeight = rectLineView?.cornerLineWidth {
let distance = rectHeight - cornerHeight - lineView.frame.height
let animation = CABasicAnimation()
......@@ -123,3 +129,9 @@ extension MRScanningProtocol where Self: UIViewController {
scanLineView?.isHidden = hide
}
}
extension MRScanningProtocol where Self: UIViewController {
private func setInterfaceTypeConfig(_ config: (scanningRect: CGRect, innerRect: CGRect)) {
objc_setAssociatedObject(self, &privateInterfaceTypeKey, config, .OBJC_ASSOCIATION_COPY_NONATOMIC)
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment