提交 069f2e8e authored 作者: 炳皓's avatar 炳皓

扫一扫浅改 1.0.0(2)打包

上级 9e4534cc
...@@ -885,7 +885,7 @@ ...@@ -885,7 +885,7 @@
CODE_SIGN_IDENTITY = "Apple Development"; CODE_SIGN_IDENTITY = "Apple Development";
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Distribution"; "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Distribution";
CODE_SIGN_STYLE = Manual; CODE_SIGN_STYLE = Manual;
CURRENT_PROJECT_VERSION = 1; CURRENT_PROJECT_VERSION = 2;
DEVELOPMENT_TEAM = ""; DEVELOPMENT_TEAM = "";
"DEVELOPMENT_TEAM[sdk=iphoneos*]" = 6GXWSJY2AD; "DEVELOPMENT_TEAM[sdk=iphoneos*]" = 6GXWSJY2AD;
EXCLUDED_ARCHS = "arm64 EXCLUDED_ARCHS__EFFECTIVE_PLATFORM_SUFFIX_simulator__NATIVE_ARCH_64_BIT_x86_64=arm64 arm64e armv7 armv7s armv6 armv8 EXCLUDED_ARCHS=$(inherited) $(EXCLUDED_ARCHS__EFFECTIVE_PLATFORM_SUFFIX_$(EFFECTIVE_PLATFORM_SUFFIX)__NATIVE_ARCH_64_BIT_$(NATIVE_ARCH_64_BIT))"; EXCLUDED_ARCHS = "arm64 EXCLUDED_ARCHS__EFFECTIVE_PLATFORM_SUFFIX_simulator__NATIVE_ARCH_64_BIT_x86_64=arm64 arm64e armv7 armv7s armv6 armv8 EXCLUDED_ARCHS=$(inherited) $(EXCLUDED_ARCHS__EFFECTIVE_PLATFORM_SUFFIX_$(EFFECTIVE_PLATFORM_SUFFIX)__NATIVE_ARCH_64_BIT_$(NATIVE_ARCH_64_BIT))";
...@@ -933,7 +933,7 @@ ...@@ -933,7 +933,7 @@
CODE_SIGN_IDENTITY = "Apple Development"; CODE_SIGN_IDENTITY = "Apple Development";
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Distribution"; "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Distribution";
CODE_SIGN_STYLE = Manual; CODE_SIGN_STYLE = Manual;
CURRENT_PROJECT_VERSION = 1; CURRENT_PROJECT_VERSION = 2;
DEVELOPMENT_TEAM = ""; DEVELOPMENT_TEAM = "";
"DEVELOPMENT_TEAM[sdk=iphoneos*]" = 6GXWSJY2AD; "DEVELOPMENT_TEAM[sdk=iphoneos*]" = 6GXWSJY2AD;
EXCLUDED_ARCHS = "EXCLUDED_ARCHS__EFFECTIVE_PLATFORM_SUFFIX_simulator__NATIVE_ARCH_64_BIT_x86_64=arm64 arm64e armv7 armv7s armv6 armv8 EXCLUDED_ARCHS=$(inherited) $(EXCLUDED_ARCHS__EFFECTIVE_PLATFORM_SUFFIX_$(EFFECTIVE_PLATFORM_SUFFIX)__NATIVE_ARCH_64_BIT_$(NATIVE_ARCH_64_BIT))"; EXCLUDED_ARCHS = "EXCLUDED_ARCHS__EFFECTIVE_PLATFORM_SUFFIX_simulator__NATIVE_ARCH_64_BIT_x86_64=arm64 arm64e armv7 armv7s armv6 armv8 EXCLUDED_ARCHS=$(inherited) $(EXCLUDED_ARCHS__EFFECTIVE_PLATFORM_SUFFIX_$(EFFECTIVE_PLATFORM_SUFFIX)__NATIVE_ARCH_64_BIT_$(NATIVE_ARCH_64_BIT))";
......
...@@ -54,7 +54,7 @@ ...@@ -54,7 +54,7 @@
</Testables> </Testables>
</TestAction> </TestAction>
<LaunchAction <LaunchAction
buildConfiguration = "Debug" buildConfiguration = "Release"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB" selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB" selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
launchStyle = "0" launchStyle = "0"
......
...@@ -15,11 +15,18 @@ class QRCodeScannerViewController: KJBaseViewController, AVCaptureMetadataOutput ...@@ -15,11 +15,18 @@ class QRCodeScannerViewController: KJBaseViewController, AVCaptureMetadataOutput
var captureSession: AVCaptureSession! var captureSession: AVCaptureSession!
var previewLayer: AVCaptureVideoPreviewLayer! var previewLayer: AVCaptureVideoPreviewLayer!
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
captureSession.startRunning()
animalAction()
}
override func viewDidLoad() { override func viewDidLoad() {
super.viewDidLoad() super.viewDidLoad()
titleL.text = "Menyapu"
// 设置 AVCaptureSession // 设置 AVCaptureSession
captureSession = AVCaptureSession() captureSession = AVCaptureSession()
...@@ -51,12 +58,12 @@ class QRCodeScannerViewController: KJBaseViewController, AVCaptureMetadataOutput ...@@ -51,12 +58,12 @@ class QRCodeScannerViewController: KJBaseViewController, AVCaptureMetadataOutput
// 设置预览图层 // 设置预览图层
previewLayer = AVCaptureVideoPreviewLayer(session: captureSession) previewLayer = AVCaptureVideoPreviewLayer(session: captureSession)
previewLayer.frame = view.layer.bounds previewLayer.frame = CGRect(x: 0, y: StatusBar_Heigh + 44, width: view.bounds.width, height:view.layer.bounds.size.height - (StatusBar_Heigh + 44))
previewLayer.videoGravity = .resizeAspectFill previewLayer.videoGravity = .resizeAspectFill
view.layer.addSublayer(previewLayer) view.layer.addSublayer(previewLayer)
// 开始扫描 // 开始扫描
captureSession.startRunning() // captureSession.startRunning()
addMaskToScannerView() addMaskToScannerView()
} }
...@@ -66,13 +73,13 @@ class QRCodeScannerViewController: KJBaseViewController, AVCaptureMetadataOutput ...@@ -66,13 +73,13 @@ class QRCodeScannerViewController: KJBaseViewController, AVCaptureMetadataOutput
// 计算正方形的位置,使其位于视图的正中心 // 计算正方形的位置,使其位于视图的正中心
let squareSize: CGFloat = 300 let squareSize: CGFloat = 300
let squareX = (view.bounds.width - squareSize) / 2 let squareX = (view.bounds.width - squareSize) / 2
let squareY = (view.bounds.height - squareSize) / 2 let squareY = (view.bounds.height - squareSize - StatusBar_Heigh - 44) / 2
// 创建四个半透明的 UIView 元素作为遮罩 // 创建四个半透明的 UIView 元素作为遮罩
let topMask = UIView(frame: CGRect(x: 0, y: 0, width: view.bounds.width, height: squareY)) let topMask = UIView(frame: CGRect(x: 0, y: StatusBar_Heigh + 44, width: view.bounds.width, height: squareY))
let bottomMask = UIView(frame: CGRect(x: 0, y: squareY + squareSize, width: view.bounds.width, height: view.bounds.height - (squareY + squareSize))) let bottomMask = UIView(frame: CGRect(x: 0, y: squareY + squareSize + StatusBar_Heigh + 44, width: view.bounds.width, height: view.bounds.height - (squareY + squareSize)))
let leftMask = UIView(frame: CGRect(x: 0, y: squareY, width: squareX, height: squareSize)) let leftMask = UIView(frame: CGRect(x: 0, y: squareY + StatusBar_Heigh + 44, width: squareX, height: squareSize))
let rightMask = UIView(frame: CGRect(x: squareX + squareSize, y: squareY, width: view.bounds.width - (squareX + squareSize), height: squareSize)) let rightMask = UIView(frame: CGRect(x: squareX + squareSize, y: squareY + StatusBar_Heigh + 44, width: view.bounds.width - (squareX + squareSize), height: squareSize))
// 设置遮罩的背景颜色 // 设置遮罩的背景颜色
[topMask, bottomMask, leftMask, rightMask].forEach { [topMask, bottomMask, leftMask, rightMask].forEach {
...@@ -81,21 +88,35 @@ class QRCodeScannerViewController: KJBaseViewController, AVCaptureMetadataOutput ...@@ -81,21 +88,35 @@ class QRCodeScannerViewController: KJBaseViewController, AVCaptureMetadataOutput
} }
// 添加绿色的正方形框 // 添加绿色的正方形框
let squareFrame = UIView(frame: CGRect(x: squareX, y: squareY, width: squareSize, height: squareSize)) let squareFrame = UIView(frame: CGRect(x: squareX, y: squareY + StatusBar_Heigh + 44, width: squareSize, height: squareSize))
squareFrame.layer.borderColor = UIColor.green.cgColor squareFrame.layer.borderColor = UIColor.green.cgColor
squareFrame.layer.borderWidth = 3 squareFrame.layer.borderWidth = 3
squareFrame.backgroundColor = .clear squareFrame.backgroundColor = .clear
view.addSubview(squareFrame) view.addSubview(squareFrame)
// 添加扫描线 // 添加扫描线
scanningLine = UIView(frame: CGRect(x: squareX, y: squareY, width: squareSize, height: 2)) scanningLine = UIView(frame: CGRect(x: squareX, y: squareY + StatusBar_Heigh + 44, width: squareSize, height: 2))
scanningLine.backgroundColor = UIColor.red scanningLine.backgroundColor = UIColor.red
view.addSubview(scanningLine) view.addSubview(scanningLine)
// 扫描线动画 // 扫描线动画
// let animation = CABasicAnimation(keyPath: "position.y")
// animation.fromValue = squareY + StatusBar_Heigh + 44
// animation.toValue = squareY + squareSize + StatusBar_Heigh + 44
// animation.duration = 2
// animation.repeatCount = .infinity
// scanningLine.layer.add(animation, forKey: "scanning")
// animalAction()
}
func animalAction() {
let squareSize: CGFloat = 300
let squareY = (view.bounds.height - squareSize - StatusBar_Heigh - 44) / 2
let animation = CABasicAnimation(keyPath: "position.y") let animation = CABasicAnimation(keyPath: "position.y")
animation.fromValue = squareY animation.fromValue = squareY + StatusBar_Heigh + 44
animation.toValue = squareY + squareSize animation.toValue = squareY + squareSize + StatusBar_Heigh + 44
animation.duration = 2 animation.duration = 2
animation.repeatCount = .infinity animation.repeatCount = .infinity
scanningLine.layer.add(animation, forKey: "scanning") scanningLine.layer.add(animation, forKey: "scanning")
...@@ -120,8 +141,26 @@ class QRCodeScannerViewController: KJBaseViewController, AVCaptureMetadataOutput ...@@ -120,8 +141,26 @@ class QRCodeScannerViewController: KJBaseViewController, AVCaptureMetadataOutput
func found(code: String) { func found(code: String) {
print("QRCode: \(code)") print("QRCode: \(code)")
// 在此处处理扫描到的 QRCode // 在此处处理扫描到的 QRCode
if code.lowercased().contains("http") {
let vc = MainWebViewController()
vc.url = code
self.navigationController?.pushViewController(vc, animated: true)
} else {
print("该字符串不包含'http'")
DispatchQueue.main.async {
self.mc_text(code , duration: 3)
self.navigationController?.popViewController(animated: true)
}
}
} }
// 其他代码,如视图将要消失时停止扫描等 // 其他代码,如视图将要消失时停止扫描等
// captureSession.startRunning()
} }
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论