Menu for ios
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
import UIKit
|
||||
import Flutter
|
||||
import DropDown
|
||||
import ZXingObjC
|
||||
|
||||
@objc class ScannerViewController: UIViewController, ZXCaptureDelegate, UITextFieldDelegate {
|
||||
|
||||
@@ -28,27 +30,17 @@ import Flutter
|
||||
}
|
||||
}
|
||||
|
||||
// @IBOutlet weak var decodedLabel: UILabel!
|
||||
|
||||
private var captureSizeTransform: CGAffineTransform?
|
||||
|
||||
var captureSizeTransform: CGAffineTransform?
|
||||
var buttonState: ButtonState = .card
|
||||
|
||||
var platformChannel: FlutterMethodChannel?
|
||||
|
||||
// Квадрат для наведения на цель (надеюсь)
|
||||
let scanRectView = UIView()
|
||||
|
||||
//Вьюшка для верхнего меню
|
||||
let topView = UIView()
|
||||
|
||||
//Окно ввода кода
|
||||
let textField = UITextField()
|
||||
|
||||
//Кнопка настроек
|
||||
var settingButton: UIButton!
|
||||
|
||||
var strings = [String:String]()
|
||||
|
||||
let scanRectView = UIView()
|
||||
let header = UIView()
|
||||
let textField = UITextField()
|
||||
let settingsButton = UIButton(type: .system)
|
||||
let searchType = UIButton(type: .system)
|
||||
let dropDown = DropDown()
|
||||
|
||||
required init?(coder aDecoder: NSCoder) {
|
||||
super.init(coder: aDecoder)
|
||||
@@ -84,32 +76,78 @@ import Flutter
|
||||
|
||||
override func viewDidLoad() {
|
||||
super.viewDidLoad()
|
||||
capture.camera = capture.back()
|
||||
capture.focusMode = .continuousAutoFocus
|
||||
|
||||
view.layer.addSublayer((capture.layer)!)
|
||||
view.addSubview(scanRectView)
|
||||
view.addSubview(header)
|
||||
view.bringSubview(toFront: header)
|
||||
view.addGestureRecognizer(UITapGestureRecognizer(target: self, action: #selector(ScannerViewController.hideKeyboard)))
|
||||
|
||||
settingButton = UIButton(type: .system)
|
||||
settingButton.addTarget(self, action: #selector(ScannerViewController.buttonTouch), for: .touchUpInside)
|
||||
|
||||
topView.addSubview(textField)
|
||||
topView.addSubview(settingButton)
|
||||
view.addSubview(topView)
|
||||
view.bringSubview(toFront: topView)
|
||||
|
||||
initCamera()
|
||||
initSearchTypeButton()
|
||||
initTextFIeld()
|
||||
initSettingsButton()
|
||||
initDropDown()
|
||||
initHeader()
|
||||
}
|
||||
|
||||
private func initCamera() {
|
||||
capture.camera = capture.back()
|
||||
capture.focusMode = .continuousAutoFocus
|
||||
}
|
||||
|
||||
private func initHeader() {
|
||||
header.addSubview(textField)
|
||||
header.addSubview(searchType)
|
||||
header.addSubview(settingsButton)
|
||||
}
|
||||
|
||||
private func initTextFIeld() {
|
||||
textField.delegate = self
|
||||
|
||||
let tap = UITapGestureRecognizer(target: self, action: #selector(ScannerViewController.hideKeyboard))
|
||||
view.addGestureRecognizer(tap)
|
||||
|
||||
settingButton.setImage(self.buttonState.icon, for: .normal)
|
||||
textField.placeholder = self.getInputHint()
|
||||
// textField.text = "79087654321"
|
||||
}
|
||||
|
||||
private func initSearchTypeButton() {
|
||||
searchType.setImage(self.buttonState.icon, for: .normal)
|
||||
searchType.addTarget(self, action: #selector(ScannerViewController.buttonTouch), for: .touchUpInside)
|
||||
}
|
||||
|
||||
private func initDropDown() {
|
||||
dropDown.anchorView = settingsButton
|
||||
dropDown.dataSource = [strings["settings"]!, strings["faq"]!]
|
||||
dropDown.selectionAction = { (index: Int, item: String) in
|
||||
if index == 0 {
|
||||
self.platformChannel?.invokeMethod("settings", arguments: nil)
|
||||
} else if index == 1 {
|
||||
self.platformChannel?.invokeMethod("faq", arguments: nil)
|
||||
}
|
||||
|
||||
self.dismiss(animated: false)
|
||||
}
|
||||
}
|
||||
|
||||
private func initSettingsButton() {
|
||||
settingsButton.setImage(UIImage(named: "more")!, for: .normal)
|
||||
settingsButton.addTarget(self, action: #selector(ScannerViewController.settingsTouch), for: .touchUpInside)
|
||||
}
|
||||
|
||||
func hideKeyboard() {
|
||||
view.endEditing(false)
|
||||
}
|
||||
|
||||
func buttonTouch() {
|
||||
setButtonState()
|
||||
searchType.setImage(self.buttonState.icon, for: .normal)
|
||||
textField.placeholder = self.getInputHint()
|
||||
}
|
||||
|
||||
func settingsTouch() {
|
||||
dropDown.show()
|
||||
}
|
||||
|
||||
override func viewWillAppear(_ animated: Bool) {
|
||||
super.viewWillAppear(animated)
|
||||
topView.backgroundColor = UIColor.white
|
||||
header.backgroundColor = UIColor.white
|
||||
textField.borderStyle = .roundedRect
|
||||
capture.delegate = self
|
||||
applyOrientation()
|
||||
@@ -118,11 +156,12 @@ import Flutter
|
||||
// TODO: Вынести эту копипасту в методы, когда будет время
|
||||
override func viewWillLayoutSubviews() {
|
||||
|
||||
// TODO: Надо бы уйти от констант, переписать на отступы какие-нибудь
|
||||
scanRectView.frame = view.bounds
|
||||
topView.frame = CGRect(x: 0, y: 0, width: view.frame.size.width, height: 56)
|
||||
settingButton.frame = CGRect(x: 8, y: 26, width: 20, height: 20)
|
||||
textField.frame = CGRect(x: settingButton.frame.maxX + 8, y: 21,
|
||||
width: view.frame.size.width - settingButton.frame.maxX - 16, height: 30)
|
||||
header.frame = CGRect(x: 0, y: 0, width: view.frame.size.width, height: 56)
|
||||
searchType.frame = CGRect(x: 8, y: 26, width: 20, height: 20)
|
||||
textField.frame = CGRect(x: searchType.frame.maxX + 8, y: 21, width: view.frame.size.width - searchType.frame.maxX - 48, height: 30)
|
||||
settingsButton.frame = CGRect(x: view.frame.size.width - 30, y: 26, width: 20, height: 20)
|
||||
|
||||
var path = UIBezierPath()
|
||||
path.move(to: CGPoint(x: 32, y: view.frame.size.height / 2))
|
||||
@@ -219,16 +258,6 @@ import Flutter
|
||||
|
||||
}
|
||||
|
||||
func hideKeyboard() {
|
||||
view.endEditing(false)
|
||||
}
|
||||
|
||||
func buttonTouch(){
|
||||
setButtonState()
|
||||
settingButton.setImage(self.buttonState.icon, for: .normal)
|
||||
textField.placeholder = self.getInputHint()
|
||||
}
|
||||
|
||||
func textFieldShouldReturn(_ textField: UITextField) -> Bool {
|
||||
print("User from manual input: \(textField.text!)")
|
||||
sendResult(textField.text!)
|
||||
|
||||
Reference in New Issue
Block a user