Swift 实现的条码扫描组件库
说明
- 支持设置不同风格的扫码动效(仿微信,仿支付宝)
- 自动检测光线强度,开启闪光灯
- 条码太小时候自动拉近镜头效果
- 自定义扫码音效
例子
直接下载代码,里面Example里面有详细的使用实例代码
!
安装
Cocoapods方式
Install Cocoapods if need be.
$ gem install cocoapods
Add GTMBarcodeScanner in your Podfile .
use_frameworks!
pod 'GTMBarcodeScanner'
Then, run the following command.
$ pod install
常规方式
Copy GTMBarcodeScanner folder to your project. That’s it.
Note: Make sure that all files in GTMBarcodeScanner included in Compile Sources in Build Phases.
版本
Vesrion 1.0
This version requires Xcode 9.0 and Swift 4.
使用帮助
首先, import GTMBarcodeScanner .
import GTMBarcodeScanner
创建Scanner
let scanner = BarcodeScanner.create(view: self.view)
scanner.makeStyle { (make) in
let color = UIColor.init(red: 255/255, green: 157/255, blue: 0/255, alpha: 1)
make.positionUpVal(44)
make.anglePosition(ScanViewStyle.AnglePosition.inner)
make.angleLineWeight(5)
make.angleLineLength(18)
make.isShowRetangleBorder(true)
make.width(280)
make.height(180)
make.retangleLineWeight(1/UIScreen.main.scale)
make.animateType(ScanViewStyle.Animation.lineMove)
make.colorOfAngleLine(color)
make.colorOfRetangleLine(color)
let c = UIColor(red: 255/255, green: 157/255, blue: 0/255, alpha: 0.5)
make.colorOutside(c)
make.soundSource(forName: "VoiceSearchOn", andType: "wav")
}
scanner.config { (make) in
make.autoCloser(true)
make.caputureImage(true)
make.printLog(true)
}
scanner.delegate = self
scanner.start()
代理对象
public protocol GTMBarcodeCoreDelegate: class {
func barcodeRecognized(result: BarcodeResult)
func lightnessChange(needFlashButton: Bool)
func barcodeForPhoto(result: BarcodeResult?)
}
风格设置
public struct ScanViewStyle {
public var isShowRetangle:Bool = true
public var size = CGSize(width: 255, height: 255)
public var positionUpVal: CGFloat = 44
public var colorRetangleLine = UIColor.white
public var colorAngleLine = UIColor(red: 0.0, green: 167.0/255.0, blue: 231.0/255.0, alpha: 1.0)
public var colorOutside = UIColor(red: 0.0, green: 0.0, blue: 0.0, alpha: 0.5)
public var anglePosition = AnglePosition.outer
public var angleW:CGFloat = 24.0
public var angleH:CGFloat = 24.0
public var angleLineWeight: CGFloat = 6
public var retangleLineWeight: CGFloat = 1
public var animateType = Animation.lineMove
public var animateImage:UIImage?
public var animateDuration: TimeInterval = 2.6
public var soundSource: (name: String, type: String)?
public init() { }
public enum Animation {
case lineMove
case gridGrow
case none
}
public enum AnglePosition {
case inner
case outer
case on
}
}
参考
本库参考了swifScan
参与开源
欢迎提交 issue 和 PR,大门永远向所有人敞开。
开源协议
本项目遵循个人协议开源,具体请查看根目录下的 LICENSE 文件。
|
请发表评论