ScanViewController.swift 2.33 KB
//
//  ScanViewController.swift
//  Twear
//
//  Created by yangbin on 2022/1/19.
//

import UIKit
import swiftScan
import SnapKit
class ScanViewController: LBXScanViewController {
    
    var isOpenedFlash: Bool = false
    
    lazy var flashButton: UIButton = {
        let button = UIButton()
//        button.backgroundColor = .red
        button.setImage(UIImage(named: "scan_flash_off"), for: .normal)
        button.addTarget(self, action: #selector(openOrCloseFlash), for: .touchUpInside)
   
        return button
    }()
    
    override func viewWillAppear(_ animated: Bool) {
        super.viewWillAppear(animated)
        self.navigationController?.setNavigationBarHidden(false, animated: true)
        self.navigationController?.navigationBar.isTranslucent = false
       
        
    }

    override func viewDidLoad() {
        super.viewDidLoad()
//        view.backgroundColor = .white
        title = LocString("扫码连接")
        
//        let y = view.frame.size.height / 2.0 + (view.frame.size.width - 120) / 2.0 - 44

        drawScanView()
        
        view.addSubview(flashButton)
        flashButton.snp.makeConstraints { make in
            make.width.height.equalTo(50)
            make.centerX.equalToSuperview()
            make.centerY.equalToSuperview().offset((SCREEN_WIDTH-120)/2-44-25)
//            make.top.equalToSuperview().offset(y)
            
//            make.bottom.equalTo(qRScanView!.snp.bottom)
        }
        
        // Do any additional setup after loading the view.
    }
    
    @objc func openOrCloseFlash() {
        scanObj?.changeTorch()

        isOpenedFlash = !isOpenedFlash
        
        if isOpenedFlash {
            flashButton.setImage(UIImage(named: "scan_flash_on"), for:UIControl.State.normal)
        } else {
            flashButton.setImage(UIImage(named: "scan_flash_off"), for:UIControl.State.normal)
        }
    }
    
//    func scanFinished(scanResult: LBXScanResult, error: String?) {
//        print(scanResult.strScanned)
//    }

    /*
    // MARK: - Navigation

    // In a storyboard-based application, you will often want to do a little preparation before navigation
    override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
        // Get the new view controller using segue.destination.
        // Pass the selected object to the new view controller.
    }
    */

}