Рамка вокруг сканнера iOS

This commit is contained in:
Ivan Murashov
2018-04-23 21:52:59 +03:00
parent bc02327b3e
commit 2d912ff2f6
8 changed files with 204 additions and 20 deletions

View File

@@ -61,22 +61,22 @@ import Flutter
func getInputHint() -> String {
switch self.buttonState {
case .card: return strings["enter_manual"]!
case .phone: return strings["enter_phone"]!
case .card: return strings["enter_manual"]!
case .phone: return strings["enter_phone"]!
}
}
func getErrorText() -> String {
switch self.buttonState {
case .card: return strings["user_card_not_found"]!
case .phone: return strings["user_phone_not_found"]!
case .card: return strings["user_card_not_found"]!
case .phone: return strings["user_phone_not_found"]!
}
}
func setButtonState() {
switch self.buttonState {
case .card: self.buttonState = .phone
case .phone: self.buttonState = .card
case .card: self.buttonState = .phone
case .phone: self.buttonState = .card
}
}
@@ -104,7 +104,7 @@ import Flutter
settingButton.setImage(self.buttonState.icon, for: .normal)
textField.placeholder = self.getInputHint()
// textField.text = "79087654321"
// textField.text = "79087654321"
}
override func viewWillAppear(_ animated: Bool) {
@@ -115,12 +115,108 @@ import Flutter
applyOrientation()
}
// TODO: Вынести эту копипасту в методы, когда будет время
override func viewWillLayoutSubviews() {
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)
var path = UIBezierPath()
path.move(to: CGPoint(x: 32, y: view.frame.size.height / 2))
path.addLine(to: CGPoint(x: view.frame.size.width - 32, y: view.frame.size.height / 2))
var shapeLayer = CAShapeLayer()
shapeLayer.path = path.cgPath
shapeLayer.strokeColor = UIColor.red.cgColor
shapeLayer.fillColor = UIColor.clear.cgColor
shapeLayer.lineWidth = 2
view.layer.addSublayer(shapeLayer)
path = UIBezierPath()
path.move(to: CGPoint(x: 32, y: (view.frame.size.height / 2) - 32))
path.addLine(to: CGPoint(x: 32, y: (view.frame.size.height / 2) - 64))
path.addLine(to: CGPoint(x: 64, y: (view.frame.size.height / 2) - 64))
path.move(to: CGPoint(x: view.frame.size.width - 64, y: (view.frame.size.height / 2) - 64))
path.addLine(to: CGPoint(x: view.frame.size.width - 32, y: (view.frame.size.height / 2) - 64))
path.addLine(to: CGPoint(x: view.frame.size.width - 32, y: (view.frame.size.height / 2) - 32))
path.move(to: CGPoint(x: 32, y: (view.frame.size.height / 2) + 32))
path.addLine(to: CGPoint(x: 32, y: (view.frame.size.height / 2) + 64))
path.addLine(to: CGPoint(x: 64, y: (view.frame.size.height / 2) + 64))
path.move(to: CGPoint(x: view.frame.size.width - 32, y: (view.frame.size.height / 2) + 32))
path.addLine(to: CGPoint(x: view.frame.size.width - 32, y: (view.frame.size.height / 2) + 64))
path.addLine(to: CGPoint(x: view.frame.size.width - 64, y: (view.frame.size.height / 2) + 64))
shapeLayer = CAShapeLayer()
shapeLayer.path = path.cgPath
shapeLayer.strokeColor = UIColor.green.cgColor
shapeLayer.fillColor = UIColor.clear.cgColor
shapeLayer.lineWidth = 2
view.layer.addSublayer(shapeLayer)
path = UIBezierPath()
path.move(to: CGPoint(x: 0, y: 56))
path.addLine(to: CGPoint(x: view.frame.size.width, y: 56))
path.addLine(to: CGPoint(x: view.frame.size.width, y: (view.frame.size.height / 2) - 64))
path.addLine(to: CGPoint(x: 0, y: (view.frame.size.height / 2) - 64))
path.addLine(to: CGPoint(x: 0, y: 56))
path.close()
shapeLayer = CAShapeLayer()
shapeLayer.path = path.cgPath
shapeLayer.fillColor = UIColor(red: 0, green: 0, blue: 0, alpha: 0.5).cgColor
view.layer.addSublayer(shapeLayer)
path = UIBezierPath()
path.move(to: CGPoint(x: 0, y: (view.frame.size.height / 2) - 64))
path.addLine(to: CGPoint(x: 32, y: (view.frame.size.height / 2) - 64))
path.addLine(to: CGPoint(x: 32, y: (view.frame.size.height / 2) + 64))
path.addLine(to: CGPoint(x: 0, y: (view.frame.size.height / 2) + 64))
path.addLine(to: CGPoint(x: 0, y: (view.frame.size.height / 2) - 64))
path.close()
shapeLayer = CAShapeLayer()
shapeLayer.path = path.cgPath
shapeLayer.fillColor = UIColor(red: 0, green: 0, blue: 0, alpha: 0.5).cgColor
view.layer.addSublayer(shapeLayer)
path = UIBezierPath()
path.move(to: CGPoint(x: view.frame.size.width, y: (view.frame.size.height / 2) - 64))
path.addLine(to: CGPoint(x: view.frame.size.width - 32, y: (view.frame.size.height / 2) - 64))
path.addLine(to: CGPoint(x: view.frame.size.width - 32, y: (view.frame.size.height / 2) + 64))
path.addLine(to: CGPoint(x: view.frame.size.width, y: (view.frame.size.height / 2) + 64))
path.addLine(to: CGPoint(x: view.frame.size.width, y: (view.frame.size.height / 2) - 64))
path.close()
shapeLayer = CAShapeLayer()
shapeLayer.path = path.cgPath
shapeLayer.fillColor = UIColor(red: 0, green: 0, blue: 0, alpha: 0.5).cgColor
view.layer.addSublayer(shapeLayer)
path = UIBezierPath()
path.move(to: CGPoint(x: view.frame.size.width, y: (view.frame.size.height / 2) + 64))
path.addLine(to: CGPoint(x: 0, y: (view.frame.size.height / 2) + 64))
path.addLine(to: CGPoint(x: 0, y: view.frame.size.height))
path.addLine(to: CGPoint(x: view.frame.size.width, y: view.frame.size.height))
path.addLine(to: CGPoint(x: view.frame.size.width, y: (view.frame.size.height / 2) + 64))
path.close()
shapeLayer = CAShapeLayer()
shapeLayer.path = path.cgPath
shapeLayer.fillColor = UIColor(red: 0, green: 0, blue: 0, alpha: 0.5).cgColor
view.layer.addSublayer(shapeLayer)
}
func hideKeyboard() {
@@ -134,7 +230,7 @@ import Flutter
}
func textFieldShouldReturn(_ textField: UITextField) -> Bool {
print("User from manual input: \(textField.text)")
print("User from manual input: \(textField.text!)")
sendResult(textField.text!)
return true
}
@@ -306,3 +402,4 @@ import Flutter
})
}
}