我正试图从代码生成按钮触发一个方法......
我收到错误:类型的值:SBSbarcode选择器没有成员StartScanning。
这个按钮如何访问上述方法?
任何帮助都将不胜感激。
class scanViewController: UIViewController {
override func viewDidLoad()
{
super.viewDidLoad()
setupManualScanner()
}
func setupManualScanner() {
// Scandit Barcode Scanner Integration
// The following method calls illustrate how the Scandit Barcode Scanner can be integrated
// into your app.
// Create the scan settings and enabling some symbologies
let settings = SBSScanSettings.default()
let symbologies: Set<SBSSymbology> = [.code39, .code128]
settings.settings(for: .code128).activeSymbolCounts = [11,15,16,17, 18]
settings.settings(for: .code39).activeSymbolCounts = [10, 14]
for symbology in symbologies
{
settings.setSymbology(symbology, enabled: true)
}
let guiOptions = SBSGuiStyle.laser
// Create the barcode picker with the settings just created
let barcodePicker = SBSBarcodePicker(settings:settings)
// Add the barcode picker as a child view controller
addChildViewController(barcodePicker)
view.addSubview(barcodePicker.view)
barcodePicker.didMove(toParentViewController: self)
// Set the allowed interface orientations. The value UIInterfaceOrientationMaskAll is the
// default and is only shown here for completeness.
barcodePicker.allowedInterfaceOrientations = .portrait
// Set custom options
barcodePicker.overlayController.setVibrateEnabled(false)
barcodePicker.overlayController.guiStyle=guiOptions
let btn: UIButton = UIButton(frame: CGRect(x: 100, y: 400, width: 100, height: 50))
btn.backgroundColor = UIColor.green
btn.setTitle("Click to scan", for: .normal)
btn.layer.cornerRadius = 10
btn.layer.masksToBounds = true
btn.addTarget(self, action: #selector(startManualScan), for: .touchUpInside)
barcodePicker.view.addSubview(btn)
// Set the delegate to receive scan event callbacks
barcodePicker.scanDelegate = self
barcodePicker.startScanning(inPausedState: true)
}
func startManualScan()
{
self.barcodePicker.startScanning()
}
答案 0 :(得分:0)
请尝试以下代码:
class scanViewController:UIViewController {
let barcodePicker = SBSBarcodePicker // declare here
override func viewDidLoad()
{
super.viewDidLoad()
setupManualScanner()
}
func setupManualScanner() {
// Scandit Barcode Scanner Integration
// The following method calls illustrate how the Scandit Barcode Scanner can be integrated
// into your app.
// Create the scan settings and enabling some symbologies
let settings = SBSScanSettings.default()
let symbologies: Set<SBSSymbology> = [.code39, .code128]
settings.settings(for: .code128).activeSymbolCounts = [11,15,16,17, 18]
settings.settings(for: .code39).activeSymbolCounts = [10, 14]
for symbology in symbologies
{
settings.setSymbology(symbology, enabled: true)
}
let guiOptions = SBSGuiStyle.laser
// Create the barcode picker with the settings just created
barcodePicker = SBSBarcodePicker(settings:settings) // made change here
//continue your code
}
func startManualScan()
{
barcodePicker.startScanning()
}