|
//
// ScanQRViewController.swift
// Paiai_iOS
//
// Created by FFIB on 16/4/8.
// Copyright © 2016年 FFIB. All rights reserved.
//
import UIKit
import AVFoundation
import PaiaiDataKit
import PaiaiUIKit
final class ScanQRViewController: UIViewController {
// MARK: Storyboard property
@IBOutlet weak var scanView: QRCodeScanView!
// MARK: parameter property
var viewModel = ScanQRViewModel()
// MARK: view function
override func viewDidLoad() {
super.viewDidLoad()
scanView.delegate = self
setNavigationBar()
viewModel.join(code: "http://pai.ai/g/SpA5be3")
}
func setNavigationBar() {
navigationItem.title = "二维码"
navigationController?.navigationBar.setBackgroundImage(UIImage.Navigation.blackBackground, for: .default)
}
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
}
override func viewWillDisappear(_ animated: Bool) {
super.viewWillDisappear(animated)
}
}
/// storyboard button action
extension ScanQRViewController {
@IBAction func openPhotoLibrary(_ sender: UIButton) {
scanView.openPhotoLibrary(ctl: self)
}
@IBAction func openLight(_ sender: UIButton) {
scanView.openLight()
}
}
// MARK: read QR message
// MARK: custom delegate function
extension ScanQRViewController: QRCodeScanViewDelegate {
func scanView(_ scanView: QRCodeScanView, didFinshWithError error: NSError?) {}
func scanView(_ scanner: QRCodeScanView, receivedScanResult: QRCodeScanResult) {
viewModel.join(code: receivedScanResult.result)
}
}
extension ScanQRViewController: NavigationBackViewController {}
extension ScanQRViewController: Storyboarded {
static func instantiate() -> ScanQRViewController {
return UIStoryboard.main.instantiateViewController(type: ScanQRViewController.self)
}
}
|