| key | type | des | true | false |
|---|---|---|---|---|
| isSingle | bool | 是否仅识别单一结果,默认true | 单一结果 | 多个结果 |
| isSquare | bool | 是否展示正方形边框,默认true | 展示 | 不展示 |
| isSingleFocu | bool | 是否开启单点聚焦,默认false | 开启 | 关闭 |
| isAutoFocus | bool | 是否开启自动对焦,默认true | 开启 | 关闭 |
| isAutoStop | bool | 是否开启自动停止扫描,默认true | 开启 | 关闭 |
| isDoubleTap | bool | 是否支持双击手势,默认true | 支持 | 不支持 |
| isZoom | bool | 是否支持缩放手势,默认true | 支持 | 不支持 |
| isHasTorch | bool | 是否支持光感检测,自动打开闪光灯,默认true | 支持 | 不支持 |
| isPromptBox | bool | 二维码类型,识别成功时,是否展示框选提示,默认true | 展示 | 不展示 |
| isLimit | bool | 是否自定义底部UI,默认false | 自定义 | 默认UI |
| isUnrestrained | bool | 是否完全自定义UI,默认false | 自定义 | 默认UI |
| isDebug | bool | 是否打印调试信息,默认true | 打印 | 不打印 |
| sound | String? | 扫描提示音,默认nil | Bundle有效资源展示 | 默认不展示 |
| animationImage | UIImage? | 扫描动画样式图,默认nil | 有效资源展示 | 默认不显示 |
| brightnessMinValue | Double | 自动开启闪光灯亮度对比值,默认true | 小于此值开启 | 默认-1 |
| brightnessMaxValue | Double | 自动关闭闪光灯亮度对比值,默认true | 大于此值关闭 | 默认6 |
| preset | AVCaptureSession.Preset | 扫描质量 | inputPriority | 默认 |
| key | type | des |
|---|---|---|
| margin | Int | 距离左右边界间距(默认60) |
| lineHeight | Int | 正方形边框粗细(默认0) |
| lineColor | UIColor | 正方形边框颜色(默认clear) |
| angleColor | UIColor | 正方形边框4个角颜色(默认orange) |
| angleLength | Int | 正方形边框4个角长度(默认30) |
| angleHeight | Int | 正方形边框4个角高度(默认4) |
| angleStyle | AngleStyle | 正方形边框边角样式(默认重合) |
| animationStyle | AnimationStyle | 扫码动画效果(默认无动画) |
| autoFocuStyle | AutoFocuStyle | 自动聚焦样式(提供默认样式) |
| highlightStyle | HighlightStyle | 二维码扫描成功时,框选提示样式(提供默认样式) |
| animationImage | UIImage | 扫码动画资源图片(可选值,若为空则无动画效果) |
| unrecognizedArea | UIColor | 非识别区域背景色(默认黑色,0.5透明度) |
| key | type | des |
|---|---|---|
| value | String | 扫描结果字符串 |
| metadataType | AVMetadataObject.ObjectType | 扫描结果类型 |
pod 'ScanHelper'import ScanHelperSDK
#import <ScanHelperSDK/ScanHelperSDK-Swift.h>
/// 让控制器持有scanHelper对象,不然会被提前释放
let scanHelper = ScanHelper()
override func viewDidLoad() {
super.viewDidLoad()
scanHelper.start(supView: view) { [weak self] (res) in
guard let self = self else { return }
print(res)
self.navigationController?.popViewController(animated: true)
}
}/// 让控制器持有scanHelper对象,不然会被提前释放
let scanHelper = ScanHelper()
override func viewDidLoad() {
super.viewDidLoad()
var config = ScanConfig()
config.sound = Bundle.main.path(forResource: "scan_audio", ofType: "wav")
config.animationImage = UIImage(named: "scan_animation")
config.isAutoFocus = false
config.isHasTorch = false
config.isZoom = false
config.isSingle = false
config.scanStyle.lineColor = .purple
config.scanStyle.angleStyle = .OutLine
config.scanStyle.anmiationStyle = .LineCenter
config.scanStyle.autoFocuStyle.lineColor = .blue
// and so on ...
scanHelper.start(supView: view, scanConfig: config) { [weak self] (res) in
guard let self = self else { return }
print(res)
self.navigationController?.popViewController(animated: true)
}
}class ScanHelperViewController: UIViewController, ScanHelperDelegate {
/// 让控制器持有scanHelper对象,不然会被提前释放
let scanHelper = ScanHelper()
override func viewDidLoad() {
super.viewDidLoad()
defaultBackgroundColor()
let config = ScanConfig()
config.isUnrestrained = true
// ⚠️⚠️⚠️scanHandler回调,仅获取单一扫描结果
// 通过代理方法,获取多个扫描结果
scanHelper.delegate = self
scanHelper.start(supView: view, scanConfig: config)
}
// MARK: - 自定义底部视图(获取一个自定义view,从扫描框底部开始计算到父视图底部边缘区域视图)
func scanLimit(_ bottomView: UIView) {
bottomView.backgroundColor = .orange
}
// MARK: - 完全自定义UI视图(获取一个自定义view,frame大小同父视图bounds)
func scanUnrestrained(_ fullView: UIView) {
let v = UIView()
v.frame = CGRect(x: 0, y: 0, width: 200, height: 200)
fullView.addSubview(v)
}
// MARK: - 获取一个亮度值
func scanCaptureOutput(_ brightnessValue: Double) {
print(brightnessValue)
}
// MARK: - 多结果返回集合,ScanResult(⚠️⚠️⚠️仅多个结果才会执行此代理方法)
func scanMetadataOutput(_ values: Array<ScanResult>) {
print(values)
}
// MARK: 反初始化器
deinit {
print("ScanHelperViewController deinit")
}
}/**
@method start:
@param supView
The incoming parent view.
@param scanConfig
ScanConfig (Default: ScanConfig()).
@param scanRegion
The valid scanning area. The default size is the same as that of the parent view.
@param scanType
The supported recognizable scanning types are the same as the system API by default.
@param scanHandler
The scan result callback
@discussion
None
*/
@available(iOS 11.0, *)
@objc func start(supView: UIView, scanConfig: ScanConfig, scanRegion: CGRect, scanType: [AVMetadataObject.ObjectType], scanHandler: ((ScanResult) -> Void)?)/**
@method stop
@discussion
None
*/
@available(iOS 11.0, *)
@objc func stop()/**
@method scanLimit:
@param bottomView
A view from the bottom of the scan box to the bottom area of the parent view.
@discussion
None
*/
@available(iOS 11.0, *)
@objc optional func scanLimit(_ bottomView: UIView)
/**
@method scanUnrestrained:
@param fullView
A view that is the same size as the parent view.
@discussion
None
*/
@available(iOS 11.0, *)
@objc optional func scanUnrestrained(_ fullView: UIView)
/**
@method scanCaptureOutput:
@param brightnessValue
A brightness value.
@discussion
None
*/
@available(iOS 11.0, *)
@objc optional func scanCaptureOutput(_ brightnessValue: Double)
/**
@method scanMetadataOutput:
@param values
An array of scan results.
@discussion
None
*/
@available(iOS 11.0, *)
@objc optional func scanMetadataOutput(_ values: Array<ScanResult>)/**
@method torchFlash:
@param open
A boolean value, the default is false.
@discussion
None
*/
@available(iOS 11.0, *)
@objc optional func torchFlash(open: Bool)/**
@method detector:
@param image
A valid picture.
@param ofType
The type is used to specify the detection intent. (Default: CIDetectorTypeQRCode).
@param context
The context argument specifies the CIContext to be used to operate on the image. may be nil. (Default: nil).
@param options
The options parameter lets you optinally specify a accuracy / performance tradeoff. can be nil or an empty dictionary. (Default: [[CIDetectorAccuracy: CIDetectorAccuracyHigh]]).
@result
An array of CIFeature instances in the given image.
@discussion
None
*/
@available(iOS 11.0, *)
@objc optional func detector(image: UIImage, ofType: String, context: CIContext?, options: [String : Any]?) -> [CIFeature]?