From 3d1c07a3374a8ad9369dcf44ca6ad15aca7908c4 Mon Sep 17 00:00:00 2001 From: zhoushisong <136296684@qq.com> Date: Wed, 17 Nov 2021 16:07:09 +0800 Subject: [PATCH 1/3] =?UTF-8?q?=E6=89=AB=E6=8F=8F=E5=8C=BA=E5=9F=9F?= =?UTF-8?q?=E6=94=AF=E6=8C=81=E8=83=8C=E6=99=AF=E5=9B=BE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Source/LBXScanView.swift | 137 +++++++++--------- Source/LBXScanViewStyle.swift | 3 + swiftScan.xcodeproj/project.pbxproj | 6 +- .../AppIcon.appiconset/Contents.json | 45 ++++-- swiftScan/Assets.xcassets/Contents.json | 6 + .../scan_border.imageset/Contents.json | 22 +++ .../scan_border.imageset/scan_border@2x.png | Bin 0 -> 6727 bytes .../scan_border.imageset/scan_border@3x.png | Bin 0 -> 13554 bytes swiftScan/QQScanViewController.swift | 1 + 9 files changed, 137 insertions(+), 83 deletions(-) create mode 100644 swiftScan/Assets.xcassets/Contents.json create mode 100644 swiftScan/Assets.xcassets/scan_border.imageset/Contents.json create mode 100644 swiftScan/Assets.xcassets/scan_border.imageset/scan_border@2x.png create mode 100644 swiftScan/Assets.xcassets/scan_border.imageset/scan_border@3x.png diff --git a/Source/LBXScanView.swift b/Source/LBXScanView.swift index abaf0f1..ee32141 100755 --- a/Source/LBXScanView.swift +++ b/Source/LBXScanView.swift @@ -181,7 +181,7 @@ open class LBXScanView: UIView { // 执行绘画 context.strokePath() - if viewStyle.isNeedShowRetangle { + if viewStyle.isNeedShowRetangle && viewStyle.scanBgImage == nil { // 中间画矩形(正方形) context.setStrokeColor(viewStyle.colorRetangleLine.cgColor) context.setLineWidth(viewStyle.widthRetangleLine) @@ -196,72 +196,79 @@ open class LBXScanView: UIView { scanRetangleRect = CGRect(x: XRetangleLeft, y: YMinRetangle, width: sizeRetangle.width, height: sizeRetangle.height) - // 画矩形框4格外围相框角 - - // 相框角的宽度和高度 - let wAngle = viewStyle.photoframeAngleW - let hAngle = viewStyle.photoframeAngleH - - // 4个角的 线的宽度 - let linewidthAngle = viewStyle.photoframeLineW // 经验参数:6和4 - - // 画扫码矩形以及周边半透明黑色坐标参数 - var diffAngle = linewidthAngle / 3 - diffAngle = linewidthAngle / 2 // 框外面4个角,与框有缝隙 - diffAngle = linewidthAngle / 2 // 框4个角 在线上加4个角效果 - diffAngle = 0 // 与矩形框重合 - - switch viewStyle.photoframeAngleStyle { - case .Outer: diffAngle = linewidthAngle / 3 // 框外面4个角,与框紧密联系在一起 - case .On: diffAngle = 0 - case .Inner: diffAngle = -viewStyle.photoframeLineW / 2 + if let bgImage = viewStyle.scanBgImage { + let imgV = UIImageView.init(image: bgImage) + let scanFrame = getScanRectForAnimation() + imgV.frame = CGRect(x: scanFrame.origin.x - 5, y: scanFrame.origin.y - 5, width: scanFrame.size.width + 10, height: scanFrame.size.height + 10) + self.addSubview(imgV) + } else { + // 画矩形框4格外围相框角 + + // 相框角的宽度和高度 + let wAngle = viewStyle.photoframeAngleW + let hAngle = viewStyle.photoframeAngleH + + // 4个角的 线的宽度 + let linewidthAngle = viewStyle.photoframeLineW // 经验参数:6和4 + + // 画扫码矩形以及周边半透明黑色坐标参数 + var diffAngle = linewidthAngle / 3 + diffAngle = linewidthAngle / 2 // 框外面4个角,与框有缝隙 + diffAngle = linewidthAngle / 2 // 框4个角 在线上加4个角效果 + diffAngle = 0 // 与矩形框重合 + + switch viewStyle.photoframeAngleStyle { + case .Outer: diffAngle = linewidthAngle / 3 // 框外面4个角,与框紧密联系在一起 + case .On: diffAngle = 0 + case .Inner: diffAngle = -viewStyle.photoframeLineW / 2 + } + + context.setStrokeColor(viewStyle.colorAngle.cgColor) + context.setFillColor(red: 1.0, green: 1.0, blue: 1.0, alpha: 1.0) + + // Draw them with a 2.0 stroke width so they are a bit more visible. + context.setLineWidth(linewidthAngle) + + + // + let leftX = XRetangleLeft - diffAngle + let topY = YMinRetangle - diffAngle + let rightX = XRetangleRight + diffAngle + let bottomY = YMaxRetangle + diffAngle + + // 左上角水平线 + context.move(to: CGPoint(x: leftX - linewidthAngle / 2, y: topY)) + context.addLine(to: CGPoint(x: leftX + wAngle, y: topY)) + + // 左上角垂直线 + context.move(to: CGPoint(x: leftX, y: topY - linewidthAngle / 2)) + context.addLine(to: CGPoint(x: leftX, y: topY + hAngle)) + + // 左下角水平线 + context.move(to: CGPoint(x: leftX - linewidthAngle / 2, y: bottomY)) + context.addLine(to: CGPoint(x: leftX + wAngle, y: bottomY)) + + // 左下角垂直线 + context.move(to: CGPoint(x: leftX, y: bottomY + linewidthAngle / 2)) + context.addLine(to: CGPoint(x: leftX, y: bottomY - hAngle)) + + // 右上角水平线 + context.move(to: CGPoint(x: rightX + linewidthAngle / 2, y: topY)) + context.addLine(to: CGPoint(x: rightX - wAngle, y: topY)) + + // 右上角垂直线 + context.move(to: CGPoint(x: rightX, y: topY - linewidthAngle / 2)) + context.addLine(to: CGPoint(x: rightX, y: topY + hAngle)) + + // 右下角水平线 + context.move(to: CGPoint(x: rightX + linewidthAngle / 2, y: bottomY)) + context.addLine(to: CGPoint(x: rightX - wAngle, y: bottomY)) + + // 右下角垂直线 + context.move(to: CGPoint(x: rightX, y: bottomY + linewidthAngle / 2)) + context.addLine(to: CGPoint(x: rightX, y: bottomY - hAngle)) } - context.setStrokeColor(viewStyle.colorAngle.cgColor) - context.setFillColor(red: 1.0, green: 1.0, blue: 1.0, alpha: 1.0) - - // Draw them with a 2.0 stroke width so they are a bit more visible. - context.setLineWidth(linewidthAngle) - - - // - let leftX = XRetangleLeft - diffAngle - let topY = YMinRetangle - diffAngle - let rightX = XRetangleRight + diffAngle - let bottomY = YMaxRetangle + diffAngle - - // 左上角水平线 - context.move(to: CGPoint(x: leftX - linewidthAngle / 2, y: topY)) - context.addLine(to: CGPoint(x: leftX + wAngle, y: topY)) - - // 左上角垂直线 - context.move(to: CGPoint(x: leftX, y: topY - linewidthAngle / 2)) - context.addLine(to: CGPoint(x: leftX, y: topY + hAngle)) - - // 左下角水平线 - context.move(to: CGPoint(x: leftX - linewidthAngle / 2, y: bottomY)) - context.addLine(to: CGPoint(x: leftX + wAngle, y: bottomY)) - - // 左下角垂直线 - context.move(to: CGPoint(x: leftX, y: bottomY + linewidthAngle / 2)) - context.addLine(to: CGPoint(x: leftX, y: bottomY - hAngle)) - - // 右上角水平线 - context.move(to: CGPoint(x: rightX + linewidthAngle / 2, y: topY)) - context.addLine(to: CGPoint(x: rightX - wAngle, y: topY)) - - // 右上角垂直线 - context.move(to: CGPoint(x: rightX, y: topY - linewidthAngle / 2)) - context.addLine(to: CGPoint(x: rightX, y: topY + hAngle)) - - // 右下角水平线 - context.move(to: CGPoint(x: rightX + linewidthAngle / 2, y: bottomY)) - context.addLine(to: CGPoint(x: rightX - wAngle, y: bottomY)) - - // 右下角垂直线 - context.move(to: CGPoint(x: rightX, y: bottomY + linewidthAngle / 2)) - context.addLine(to: CGPoint(x: rightX, y: bottomY - hAngle)) - context.strokePath() } diff --git a/Source/LBXScanViewStyle.swift b/Source/LBXScanViewStyle.swift index 0218ac6..18fd214 100644 --- a/Source/LBXScanViewStyle.swift +++ b/Source/LBXScanViewStyle.swift @@ -68,6 +68,9 @@ public struct LBXScanViewStyle { /// 动画效果的图像,如线条或网格的图像 public var animationImage: UIImage? + + /// 扫码区域的背景图片 + public var scanBgImage: UIImage? //MARK: - 非识别区域颜色, 默认 RGBA (0,0,0,0.5),范围(0--1) diff --git a/swiftScan.xcodeproj/project.pbxproj b/swiftScan.xcodeproj/project.pbxproj index e1e6e4f..3de4755 100755 --- a/swiftScan.xcodeproj/project.pbxproj +++ b/swiftScan.xcodeproj/project.pbxproj @@ -177,7 +177,7 @@ TargetAttributes = { 7D42B9AB1C05EE9A0084D045 = { CreatedOnToolsVersion = 7.1; - DevelopmentTeam = 8LQ7CL73D8; + DevelopmentTeam = 9HV4B937SU; LastSwiftMigration = 0820; ProvisioningStyle = Automatic; }; @@ -378,11 +378,11 @@ CODE_SIGN_IDENTITY = "iPhone Developer"; "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; CODE_SIGN_STYLE = Automatic; - DEVELOPMENT_TEAM = 8LQ7CL73D8; + DEVELOPMENT_TEAM = 9HV4B937SU; INFOPLIST_FILE = swiftScan/Info.plist; IPHONEOS_DEPLOYMENT_TARGET = 8.0; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; - PRODUCT_BUNDLE_IDENTIFIER = com.lbx.hk2019235; + PRODUCT_BUNDLE_IDENTIFIER = com.zhouss.scan; PRODUCT_NAME = "$(TARGET_NAME)"; PROVISIONING_PROFILE = "5afb03a3-32bd-412b-9db2-5fa2d3271415"; PROVISIONING_PROFILE_SPECIFIER = ""; diff --git a/swiftScan/Assets.xcassets/AppIcon.appiconset/Contents.json b/swiftScan/Assets.xcassets/AppIcon.appiconset/Contents.json index 118c98f..8121323 100644 --- a/swiftScan/Assets.xcassets/AppIcon.appiconset/Contents.json +++ b/swiftScan/Assets.xcassets/AppIcon.appiconset/Contents.json @@ -2,37 +2,52 @@ "images" : [ { "idiom" : "iphone", - "size" : "29x29", - "scale" : "2x" + "scale" : "2x", + "size" : "20x20" }, { "idiom" : "iphone", - "size" : "29x29", - "scale" : "3x" + "scale" : "3x", + "size" : "20x20" }, { "idiom" : "iphone", - "size" : "40x40", - "scale" : "2x" + "scale" : "2x", + "size" : "29x29" }, { "idiom" : "iphone", - "size" : "40x40", - "scale" : "3x" + "scale" : "3x", + "size" : "29x29" }, { "idiom" : "iphone", - "size" : "60x60", - "scale" : "2x" + "scale" : "2x", + "size" : "40x40" }, { "idiom" : "iphone", - "size" : "60x60", - "scale" : "3x" + "scale" : "3x", + "size" : "40x40" + }, + { + "idiom" : "iphone", + "scale" : "2x", + "size" : "60x60" + }, + { + "idiom" : "iphone", + "scale" : "3x", + "size" : "60x60" + }, + { + "idiom" : "ios-marketing", + "scale" : "1x", + "size" : "1024x1024" } ], "info" : { - "version" : 1, - "author" : "xcode" + "author" : "xcode", + "version" : 1 } -} \ No newline at end of file +} diff --git a/swiftScan/Assets.xcassets/Contents.json b/swiftScan/Assets.xcassets/Contents.json new file mode 100644 index 0000000..73c0059 --- /dev/null +++ b/swiftScan/Assets.xcassets/Contents.json @@ -0,0 +1,6 @@ +{ + "info" : { + "author" : "xcode", + "version" : 1 + } +} diff --git a/swiftScan/Assets.xcassets/scan_border.imageset/Contents.json b/swiftScan/Assets.xcassets/scan_border.imageset/Contents.json new file mode 100644 index 0000000..5396847 --- /dev/null +++ b/swiftScan/Assets.xcassets/scan_border.imageset/Contents.json @@ -0,0 +1,22 @@ +{ + "images" : [ + { + "idiom" : "universal", + "scale" : "1x" + }, + { + "filename" : "scan_border@2x.png", + "idiom" : "universal", + "scale" : "2x" + }, + { + "filename" : "scan_border@3x.png", + "idiom" : "universal", + "scale" : "3x" + } + ], + "info" : { + "author" : "xcode", + "version" : 1 + } +} diff --git a/swiftScan/Assets.xcassets/scan_border.imageset/scan_border@2x.png b/swiftScan/Assets.xcassets/scan_border.imageset/scan_border@2x.png new file mode 100644 index 0000000000000000000000000000000000000000..ea3a1661d8a89c60e4aa20b909d53219be5caf23 GIT binary patch literal 6727 zcmeI1`&-gk8o+_25icc87dI+#tL-wbmu=E9?{<0AY|K)Eydc?QY?`vgSSlpK>}WUb z>LpQmT(>k#Xfq-&fefRKiP}Zf(E<&l)DRK5Dezrj=Gnhse%WXF;XLp2oa=ku^PY3w z^EsE|Vk4J3A)G)U(DLZ0eMdkbu*jNVUs!T5W0ge~0VW=a+yi3uZ z+)`>f0SlR}>tobBez`Y7(8tQhe0BT4xv5RlZHSndZ4`O?!97ul^i*DSErD(@Vp}gs z^X5s|0UusX^vR;C#muZMd{%NG##57vQrt&`9rFuLK)D{=cqTRUn`~*k!wRF3N6x~o z21B5;Zq$|r?O=d;p&)Pfc|+h(Q@1lpn2FM~j5bzeq-(xYNCElnJYg0xe@Zml_E;rG zJoiZu7iTXSkCMWDx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^^(n=kKGlc}f!SeN_|VRQ74}*JDPX0VnxuV;*-q7^3rd z7%U*SvK|Bz)%bF**+sobA!?Mn&b!}7@OP?G2PDEjhjzNI5xK&pgl`Kw%UAyFD$f_s zy=$A3znY=o4YOl!%}M_L{120_yV02&_TQt!ex$T&O`gKNN#>SA0x|`7X?O>Nk5oa{36j|epM>RX plz1Sc9?L8fzu`~-dVJ|Tko9dv#_}@+iryc)kF^I!`wx^i9i0FG literal 0 HcmV?d00001 diff --git a/swiftScan/Assets.xcassets/scan_border.imageset/scan_border@3x.png b/swiftScan/Assets.xcassets/scan_border.imageset/scan_border@3x.png new file mode 100644 index 0000000000000000000000000000000000000000..c8e1afadea5841b129ac50587d95b73a27f20cd1 GIT binary patch literal 13554 zcmeHOX;hQfx&{grvQGABSK32hL?sK8+~2nYs32qb|_H$lO(y6(Dbo!{sCk(IT-VGqxK_xnD3 zf6tqL1QE1#v*l(jEv>DG4h9_6($cBd{PaIoUvW(L$x;7lUpN}%uT|S?J)@;%t92+~ z|2JvJ=SHHdC*!{Dc(pw5!!2T&Q7_{l(i?%g_wo z5m#P)TeQ^hwhdDr_m~O2&s7!?Po@;`L=jnjXgieJ2hg)E$xpeK?37-?KTBsb4VqO868y*4B=xg`w7^XrKfkVg8I6M^9S$=x=p=b_B= znNC#c4GVNbU#=2+)UVs26K|~P>m>&r|Ar|e?n69Cwf(`&PTF(`R+0c-?15k;Bi<92 z>gev&$!qrV&-Oq5)y}`Ws4s)8X-ogd&H95!M{zQg1T;Qp43dInAZ=sSa2Sl1XYdCl#c!|iXW0g34?>x^=w+)! zQK->h#?$IvS;~v)DNf300lTKn3c72RDVM#s(e2C%hU{6tMm`wvP?6%Q_l9C&EuQxmszY$_PMKi zdHfw8XBAB!!)hgX`0n8B6cFi{aBN6FTIJ&&L)t07LZ-qO!xPSqM9WXsIX@JC{muY` z)gZXuYwnG#MByb}FJ#Ikm3lx(eu=ZM%34XweL-=MebptEk(qNaGYW}2owe76A+>s& z&~P@6A)g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M@)i zhtF1}Lt1Nk=hjr3mo6MsC);H9z-)-Pq`+Wg!I?}LOL~p$EV#ZRM@}peZ_zLk&k5T7 ekzuTAYjfDsi>N;zn5vVQv<@9W1l0PUxctAjPl>Sr literal 0 HcmV?d00001 diff --git a/swiftScan/QQScanViewController.swift b/swiftScan/QQScanViewController.swift index 777c363..f53ae46 100644 --- a/swiftScan/QQScanViewController.swift +++ b/swiftScan/QQScanViewController.swift @@ -42,6 +42,7 @@ class QQScanViewController: LBXScanViewController { //框向上移动10个像素 scanStyle?.centerUpOffset += 10 + scanStyle?.scanBgImage = UIImage.init(named: "scan_border") // Do any additional setup after loading the view. } From f593877790fe55fdf793c89493e9b23595bb76e9 Mon Sep 17 00:00:00 2001 From: zhoushisong <136296684@qq.com> Date: Fri, 19 Nov 2021 14:59:08 +0800 Subject: [PATCH 2/3] =?UTF-8?q?feat:=20=E6=96=B0=E5=A2=9E=E5=AF=B9?= =?UTF-8?q?=E7=8E=AF=E5=A2=83=E5=85=89=E7=BA=BF=E7=9A=84=E7=9B=91=E5=90=AC?= =?UTF-8?q?=EF=BC=8C=E4=BB=A5=E4=BE=BF=E8=87=AA=E5=8A=A8=E5=BC=80=E5=90=AF?= =?UTF-8?q?=E6=89=8B=E7=94=B5=E7=AD=92?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Source/LBXScanViewController.swift | 29 ++++++++++++++-------------- Source/LBXScanWrapper.swift | 28 +++++++++++++++++++++++++-- swiftScan/QQScanViewController.swift | 8 ++++++++ 3 files changed, 48 insertions(+), 17 deletions(-) diff --git a/Source/LBXScanViewController.swift b/Source/LBXScanViewController.swift index e0375de..5fee6f3 100755 --- a/Source/LBXScanViewController.swift +++ b/Source/LBXScanViewController.swift @@ -84,21 +84,18 @@ open class LBXScanViewController: UIViewController { AVMetadataObject.ObjectType.ean13 as NSString, AVMetadataObject.ObjectType.code128 as NSString] as [AVMetadataObject.ObjectType] } - - scanObj = LBXScanWrapper(videoPreView: view, - objType: arrayCodeType!, - isCaptureImg: isNeedCodeImage, - cropRect: cropRect, - success: { [weak self] (arrayResult) -> Void in - guard let strongSelf = self else { - return - } - if !strongSelf.isSupportContinuous { - // 停止扫描动画 - strongSelf.qRScanView?.stopScanAnimation() - } - strongSelf.handleCodeResult(arrayResult: arrayResult) - }) + + scanObj = LBXScanWrapper(videoPreView: view, objType: arrayCodeType!, isCaptureImg: isNeedCodeImage, cropRect: cropRect, success: { [weak self] (arrayResult) -> Void in + guard let strongSelf = self else { return } + if !strongSelf.isSupportContinuous { + // 停止扫描动画 + strongSelf.qRScanView?.stopScanAnimation() + } + strongSelf.handleCodeResult(arrayResult: arrayResult) + }, ambientLightValueClosure: { [weak self] value in + guard let strongSelf = self else { return } + strongSelf.ambientLightValueDidChange(value: value) + }) } scanObj?.supportContinuous = isSupportContinuous; @@ -144,6 +141,8 @@ open class LBXScanViewController: UIViewController { } } + open func ambientLightValueDidChange(value: Double) {} + open override func viewWillDisappear(_ animated: Bool) { NSObject.cancelPreviousPerformRequests(withTarget: self) qRScanView?.stopScanAnimation() diff --git a/Source/LBXScanWrapper.swift b/Source/LBXScanWrapper.swift index 126441c..5ee8905 100755 --- a/Source/LBXScanWrapper.swift +++ b/Source/LBXScanWrapper.swift @@ -33,11 +33,12 @@ public struct LBXScanResult { -open class LBXScanWrapper: NSObject,AVCaptureMetadataOutputObjectsDelegate { +open class LBXScanWrapper: NSObject, AVCaptureMetadataOutputObjectsDelegate, AVCaptureVideoDataOutputSampleBufferDelegate { let device = AVCaptureDevice.default(for: AVMediaType.video) var input: AVCaptureDeviceInput? var output: AVCaptureMetadataOutput + var videoDataOutput: AVCaptureVideoDataOutput let session = AVCaptureSession() var previewLayer: AVCaptureVideoPreviewLayer? @@ -58,6 +59,8 @@ open class LBXScanWrapper: NSObject,AVCaptureMetadataOutputObjectsDelegate { //连续扫码 var supportContinuous = false + /// 自动开启闪光灯后回调 + var ambientLightValueClosure: ((Double) -> Void)? /** 初始化设备 @@ -72,10 +75,13 @@ open class LBXScanWrapper: NSObject,AVCaptureMetadataOutputObjectsDelegate { objType: [AVMetadataObject.ObjectType] = [(AVMetadataObject.ObjectType.qr as NSString) as AVMetadataObject.ObjectType], isCaptureImg: Bool, cropRect: CGRect = .zero, - success: @escaping (([LBXScanResult]) -> Void)) { + success: @escaping (([LBXScanResult]) -> Void), + ambientLightValueClosure: ((Double) -> Void)? = nil) { + self.ambientLightValueClosure = ambientLightValueClosure successBlock = success output = AVCaptureMetadataOutput() + videoDataOutput = AVCaptureVideoDataOutput() isNeedCaptureImage = isCaptureImg stillImageOutput = AVCaptureStillImageOutput() @@ -104,6 +110,11 @@ open class LBXScanWrapper: NSObject,AVCaptureMetadataOutputObjectsDelegate { if session.canAddOutput(stillImageOutput) { session.addOutput(stillImageOutput) } + + if session.canAddOutput(videoDataOutput) { + session.addOutput(videoDataOutput) + videoDataOutput.setSampleBufferDelegate(self, queue: DispatchQueue.main) + } stillImageOutput.outputSettings = [AVVideoCodecJPEG: AVVideoCodecKey] @@ -147,6 +158,19 @@ open class LBXScanWrapper: NSObject,AVCaptureMetadataOutputObjectsDelegate { captureOutput(output, didOutputMetadataObjects: metadataObjects, from: connection) } + public func captureOutput(_ output: AVCaptureOutput, didOutput sampleBuffer: CMSampleBuffer, from connection: AVCaptureConnection) { + + if let metadata = CMCopyDictionaryOfAttachments(allocator: nil, target: sampleBuffer, attachmentMode: kCMAttachmentMode_ShouldPropagate) as? [String: Any] { + let exifKey = kCGImagePropertyExifDictionary as String + if let exifMetadata = metadata[exifKey] as? [String: Any] { + let brightlessKey = kCGImagePropertyExifBrightnessValue as String + if let brightlessVal: Double = exifMetadata[brightlessKey] as? Double { + ambientLightValueClosure?(brightlessVal) + } + } + } + } + func start() { if !session.isRunning { isNeedScanResult = true diff --git a/swiftScan/QQScanViewController.swift b/swiftScan/QQScanViewController.swift index f53ae46..d11d4ab 100644 --- a/swiftScan/QQScanViewController.swift +++ b/swiftScan/QQScanViewController.swift @@ -68,6 +68,14 @@ class QQScanViewController: LBXScanViewController { vc.codeResult = result navigationController?.pushViewController(vc, animated: true) } + + override func ambientLightValueDidChange(value: Double) { + if value < 0 { + scanObj?.setTorch(torch: true) + isOpenedFlash = true + btnFlash.setImage(UIImage(named: "CodeScan.bundle/qrcode_scan_btn_flash_down"), for:UIControl.State.normal) + } + } func drawBottomItems() { if (bottomItemsView != nil) { From def7063f2bce1e7eff9d8a1bd55ee90da4e80372 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=91=A8=E8=AF=97=E6=9D=BE?= Date: Tue, 7 Dec 2021 16:50:18 +0800 Subject: [PATCH 3/3] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E6=9C=AA=E8=AF=86?= =?UTF-8?q?=E5=88=AB=E5=88=B0=E5=9B=BE=E7=89=87=E4=B8=AD=E6=9C=89=E6=9C=89?= =?UTF-8?q?=E4=BA=8C=E7=BB=B4=E7=A0=81=E7=9A=84=E5=88=A4=E6=96=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Source/LBXScanViewController.swift | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/Source/LBXScanViewController.swift b/Source/LBXScanViewController.swift index 5fee6f3..8578811 100755 --- a/Source/LBXScanViewController.swift +++ b/Source/LBXScanViewController.swift @@ -46,6 +46,9 @@ open class LBXScanViewController: UIViewController { // 相机启动提示文字 public var readyString: String! = "loading" + /// 没有从图片中识别到二维码 + public var scanImageFailure: (() -> Void)? + open override func viewDidLoad() { super.viewDidLoad() @@ -176,6 +179,8 @@ extension LBXScanViewController: UIImagePickerControllerDelegate, UINavigationCo let arrayResult = LBXScanWrapper.recognizeQRImage(image: image) if !arrayResult.isEmpty { handleCodeResult(arrayResult: arrayResult) + } else { + scanImageFailure?() } }