Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
R
rire-tool
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
逄仁秀
rire-tool
Commits
069f2e8e
提交
069f2e8e
authored
2月 01, 2024
作者:
炳皓
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
扫一扫浅改 1.0.0(2)打包
上级
9e4534cc
隐藏空白字符变更
内嵌
并排
正在显示
3 个修改的文件
包含
64 行增加
和
25 行删除
+64
-25
project.pbxproj
iOS-2kj.xcodeproj/project.pbxproj
+2
-2
iOS-2kj.xcscheme
iOS-2kj.xcodeproj/xcshareddata/xcschemes/iOS-2kj.xcscheme
+1
-1
QRCodeScannerViewController.swift
iOS-2kj/base/QRCodeScannerViewController.swift
+61
-22
没有找到文件。
iOS-2kj.xcodeproj/project.pbxproj
浏览文件 @
069f2e8e
...
@@ -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))"
;
...
...
iOS-2kj.xcodeproj/xcshareddata/xcschemes/iOS-2kj.xcscheme
浏览文件 @
069f2e8e
...
@@ -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"
...
...
iOS-2kj/base/QRCodeScannerViewController.swift
浏览文件 @
069f2e8e
...
@@ -15,49 +15,56 @@ class QRCodeScannerViewController: KJBaseViewController, AVCaptureMetadataOutput
...
@@ -15,49 +15,56 @@ 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
()
guard
let
videoCaptureDevice
=
AVCaptureDevice
.
default
(
for
:
.
video
)
else
{
return
}
guard
let
videoCaptureDevice
=
AVCaptureDevice
.
default
(
for
:
.
video
)
else
{
return
}
let
videoInput
:
AVCaptureDeviceInput
let
videoInput
:
AVCaptureDeviceInput
do
{
do
{
videoInput
=
try
AVCaptureDeviceInput
(
device
:
videoCaptureDevice
)
videoInput
=
try
AVCaptureDeviceInput
(
device
:
videoCaptureDevice
)
}
catch
{
}
catch
{
return
return
}
}
if
captureSession
.
canAddInput
(
videoInput
)
{
if
captureSession
.
canAddInput
(
videoInput
)
{
captureSession
.
addInput
(
videoInput
)
captureSession
.
addInput
(
videoInput
)
}
else
{
}
else
{
return
return
}
}
let
metadataOutput
=
AVCaptureMetadataOutput
()
let
metadataOutput
=
AVCaptureMetadataOutput
()
if
captureSession
.
canAddOutput
(
metadataOutput
)
{
if
captureSession
.
canAddOutput
(
metadataOutput
)
{
captureSession
.
addOutput
(
metadataOutput
)
captureSession
.
addOutput
(
metadataOutput
)
metadataOutput
.
setMetadataObjectsDelegate
(
self
,
queue
:
DispatchQueue
.
main
)
metadataOutput
.
setMetadataObjectsDelegate
(
self
,
queue
:
DispatchQueue
.
main
)
metadataOutput
.
metadataObjectTypes
=
[
.
qr
]
metadataOutput
.
metadataObjectTypes
=
[
.
qr
]
}
else
{
}
else
{
return
return
}
}
// 设置预览图层
// 设置预览图层
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
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论