├── README.md
├── picture
├── IMG_0893.jpg
├── IMG_0895.jpg
├── IMG_0897.jpg
└── IMG_0898.jpg
├── scanCodeBarCode.xcodeproj
├── project.pbxproj
├── project.xcworkspace
│ ├── contents.xcworkspacedata
│ └── xcuserdata
│ │ └── ailishi.xcuserdatad
│ │ └── UserInterfaceState.xcuserstate
└── xcuserdata
│ └── ailishi.xcuserdatad
│ ├── xcdebugger
│ └── Breakpoints_v2.xcbkptlist
│ └── xcschemes
│ ├── scanCodeBarCode.xcscheme
│ └── xcschememanagement.plist
└── scanCodeBarCode
├── AppDelegate.swift
├── Assets.xcassets
├── AppIcon.appiconset
│ └── Contents.json
├── Contents.json
├── QrDefault.imageset
│ ├── Contents.json
│ └── QrDefault@2x.jpg
├── ScanQR1_16x16_.imageset
│ ├── Contents.json
│ ├── ScanQR1_16x16_@2x.png
│ └── ScanQR1_16x16_@3x.png
├── ScanQR2_16x16_.imageset
│ ├── Contents.json
│ ├── ScanQR2_16x16_@2x.png
│ └── ScanQR2_16x16_@3x.png
├── ScanQR3_16x16_.imageset
│ ├── Contents.json
│ ├── ScanQR3_16x16_@2x.png
│ └── ScanQR3_16x16_@3x.png
├── ScanQR4_16x16_.imageset
│ ├── Contents.json
│ ├── ScanQR4_16x16_@2x.png
│ └── ScanQR4_16x16_@3x.png
├── ScanWord_35x35_.imageset
│ ├── Contents.json
│ ├── ScanWord_35x35_@2x.png
│ └── ScanWord_35x35_@3x.png
├── ScanWord_HL_35x35_.imageset
│ ├── Contents.json
│ ├── ScanWord_HL_35x35_@2x.png
│ └── ScanWord_HL_35x35_@3x.png
├── barcodeScan0.imageset
│ ├── Contents.json
│ └── barcodeScan0@2x.png
├── barcodeScan1.imageset
│ ├── Contents.json
│ └── barcodeScan1@2x.png
├── erweima_1.imageset
│ ├── Contents.json
│ └── erweima_1@2x.png
├── line-1.imageset
│ ├── Contents.json
│ └── line@2x.png
├── line.imageset
│ ├── Contents.json
│ └── 线.png
├── qrcode_scan_btn_flash_off.imageset
│ ├── Contents.json
│ └── qrcode_scan_btn_flash_off@2x.png
├── qrcode_scan_btn_flash_on.imageset
│ ├── Contents.json
│ └── qrcode_scan_btn_flash_on@2x.png
├── qrcode_scan_btn_myqrcode_down.imageset
│ ├── Contents.json
│ └── qrcode_scan_btn_myqrcode_down@2x.png
├── qrcode_scan_btn_myqrcode_nor.imageset
│ ├── Contents.json
│ └── qrcode_scan_btn_myqrcode_nor@2x.png
├── qrcode_scan_full_net.imageset
│ ├── Contents.json
│ └── qrcode_scan_full_net.png
├── qrcode_scan_part_net.imageset
│ ├── Contents.json
│ └── qrcode_scan_part_net.png
└── scanScanBg1.imageset
│ ├── Contents.json
│ └── scanScanBg1.png
├── Base.lproj
├── LaunchScreen.storyboard
└── Main.storyboard
├── Category.swift
├── Const.swift
├── Info.plist
├── MineQRCodeViewController.swift
├── QRCodeReaderView.swift
├── QRCodeViewController.swift
├── ViewController.swift
└── noticeMusic.wav
/README.md:
--------------------------------------------------------------------------------
1 | # QRCodeReaderView-Swift
2 |
3 |
4 |
5 |
6 | 什么是QRCodeReaderView-Swift
7 | 基于swift语言实现二维码条形码扫描,以及二维码的生成(请使用真机运行)
8 |
9 | 效果图展示
10 |
11 | 二维码扫描关灯效果
12 | 
13 | 开灯效果
14 | 
15 | 条形码扫描
16 | 
17 | 二维码生成
18 | 
19 |
20 |
21 | 使用方法
22 | demo里面有详细标注,这里不再做展示
23 |
24 |
25 |
--------------------------------------------------------------------------------
/picture/IMG_0893.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zhanghongdou/QRCodeReaderView-Swift/ef069e0193081ff821440675804bad5a17933e0b/picture/IMG_0893.jpg
--------------------------------------------------------------------------------
/picture/IMG_0895.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zhanghongdou/QRCodeReaderView-Swift/ef069e0193081ff821440675804bad5a17933e0b/picture/IMG_0895.jpg
--------------------------------------------------------------------------------
/picture/IMG_0897.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zhanghongdou/QRCodeReaderView-Swift/ef069e0193081ff821440675804bad5a17933e0b/picture/IMG_0897.jpg
--------------------------------------------------------------------------------
/picture/IMG_0898.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zhanghongdou/QRCodeReaderView-Swift/ef069e0193081ff821440675804bad5a17933e0b/picture/IMG_0898.jpg
--------------------------------------------------------------------------------
/scanCodeBarCode.xcodeproj/project.pbxproj:
--------------------------------------------------------------------------------
1 | // !$*UTF8*$!
2 | {
3 | archiveVersion = 1;
4 | classes = {
5 | };
6 | objectVersion = 46;
7 | objects = {
8 |
9 | /* Begin PBXBuildFile section */
10 | 049165051D62B8DA0057F423 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 049165041D62B8DA0057F423 /* AppDelegate.swift */; };
11 | 049165071D62B8DA0057F423 /* ViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 049165061D62B8DA0057F423 /* ViewController.swift */; };
12 | 0491650A1D62B8DA0057F423 /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 049165081D62B8DA0057F423 /* Main.storyboard */; };
13 | 0491650C1D62B8DA0057F423 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 0491650B1D62B8DA0057F423 /* Assets.xcassets */; };
14 | 0491650F1D62B8DA0057F423 /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 0491650D1D62B8DA0057F423 /* LaunchScreen.storyboard */; };
15 | 049165191D62B8EC0057F423 /* QRCodeViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 049165161D62B8EC0057F423 /* QRCodeViewController.swift */; };
16 | 0491651A1D62B8EC0057F423 /* QRCodeReaderView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 049165171D62B8EC0057F423 /* QRCodeReaderView.swift */; };
17 | 0491651B1D62B8EC0057F423 /* MineQRCodeViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 049165181D62B8EC0057F423 /* MineQRCodeViewController.swift */; };
18 | 0491651F1D62B8F50057F423 /* Category.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0491651C1D62B8F50057F423 /* Category.swift */; };
19 | 049165201D62B8F50057F423 /* Const.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0491651D1D62B8F50057F423 /* Const.swift */; };
20 | 049165211D62B8F50057F423 /* noticeMusic.wav in Resources */ = {isa = PBXBuildFile; fileRef = 0491651E1D62B8F50057F423 /* noticeMusic.wav */; };
21 | /* End PBXBuildFile section */
22 |
23 | /* Begin PBXFileReference section */
24 | 049165011D62B8DA0057F423 /* scanCodeBarCode.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = scanCodeBarCode.app; sourceTree = BUILT_PRODUCTS_DIR; };
25 | 049165041D62B8DA0057F423 /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = ""; };
26 | 049165061D62B8DA0057F423 /* ViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ViewController.swift; sourceTree = ""; };
27 | 049165091D62B8DA0057F423 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = ""; };
28 | 0491650B1D62B8DA0057F423 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; };
29 | 0491650E1D62B8DA0057F423 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = ""; };
30 | 049165101D62B8DA0057F423 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; };
31 | 049165161D62B8EC0057F423 /* QRCodeViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = QRCodeViewController.swift; sourceTree = ""; };
32 | 049165171D62B8EC0057F423 /* QRCodeReaderView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = QRCodeReaderView.swift; path = scanCodeBarCode/QRCodeReaderView.swift; sourceTree = SOURCE_ROOT; };
33 | 049165181D62B8EC0057F423 /* MineQRCodeViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MineQRCodeViewController.swift; sourceTree = ""; };
34 | 0491651C1D62B8F50057F423 /* Category.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = Category.swift; path = ../Category.swift; sourceTree = ""; };
35 | 0491651D1D62B8F50057F423 /* Const.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = Const.swift; path = ../Const.swift; sourceTree = ""; };
36 | 0491651E1D62B8F50057F423 /* noticeMusic.wav */ = {isa = PBXFileReference; lastKnownFileType = audio.wav; name = noticeMusic.wav; path = ../noticeMusic.wav; sourceTree = ""; };
37 | /* End PBXFileReference section */
38 |
39 | /* Begin PBXFrameworksBuildPhase section */
40 | 049164FE1D62B8DA0057F423 /* Frameworks */ = {
41 | isa = PBXFrameworksBuildPhase;
42 | buildActionMask = 2147483647;
43 | files = (
44 | );
45 | runOnlyForDeploymentPostprocessing = 0;
46 | };
47 | /* End PBXFrameworksBuildPhase section */
48 |
49 | /* Begin PBXGroup section */
50 | 048275B11D6314D7000482B6 /* QRCodeReaderView */ = {
51 | isa = PBXGroup;
52 | children = (
53 | 049165171D62B8EC0057F423 /* QRCodeReaderView.swift */,
54 | );
55 | path = QRCodeReaderView;
56 | sourceTree = "";
57 | };
58 | 048275B21D6314EE000482B6 /* Common */ = {
59 | isa = PBXGroup;
60 | children = (
61 | 0491651D1D62B8F50057F423 /* Const.swift */,
62 | 0491651C1D62B8F50057F423 /* Category.swift */,
63 | 0491651E1D62B8F50057F423 /* noticeMusic.wav */,
64 | );
65 | path = Common;
66 | sourceTree = "";
67 | };
68 | 049164F81D62B8DA0057F423 = {
69 | isa = PBXGroup;
70 | children = (
71 | 049165031D62B8DA0057F423 /* scanCodeBarCode */,
72 | 049165021D62B8DA0057F423 /* Products */,
73 | );
74 | sourceTree = "";
75 | };
76 | 049165021D62B8DA0057F423 /* Products */ = {
77 | isa = PBXGroup;
78 | children = (
79 | 049165011D62B8DA0057F423 /* scanCodeBarCode.app */,
80 | );
81 | name = Products;
82 | sourceTree = "";
83 | };
84 | 049165031D62B8DA0057F423 /* scanCodeBarCode */ = {
85 | isa = PBXGroup;
86 | children = (
87 | 049165041D62B8DA0057F423 /* AppDelegate.swift */,
88 | 049165061D62B8DA0057F423 /* ViewController.swift */,
89 | 049165161D62B8EC0057F423 /* QRCodeViewController.swift */,
90 | 049165181D62B8EC0057F423 /* MineQRCodeViewController.swift */,
91 | 048275B21D6314EE000482B6 /* Common */,
92 | 048275B11D6314D7000482B6 /* QRCodeReaderView */,
93 | 049165081D62B8DA0057F423 /* Main.storyboard */,
94 | 0491650B1D62B8DA0057F423 /* Assets.xcassets */,
95 | 0491650D1D62B8DA0057F423 /* LaunchScreen.storyboard */,
96 | 049165101D62B8DA0057F423 /* Info.plist */,
97 | );
98 | path = scanCodeBarCode;
99 | sourceTree = "";
100 | };
101 | /* End PBXGroup section */
102 |
103 | /* Begin PBXNativeTarget section */
104 | 049165001D62B8DA0057F423 /* scanCodeBarCode */ = {
105 | isa = PBXNativeTarget;
106 | buildConfigurationList = 049165131D62B8DA0057F423 /* Build configuration list for PBXNativeTarget "scanCodeBarCode" */;
107 | buildPhases = (
108 | 049164FD1D62B8DA0057F423 /* Sources */,
109 | 049164FE1D62B8DA0057F423 /* Frameworks */,
110 | 049164FF1D62B8DA0057F423 /* Resources */,
111 | );
112 | buildRules = (
113 | );
114 | dependencies = (
115 | );
116 | name = scanCodeBarCode;
117 | productName = scanCodeBarCode;
118 | productReference = 049165011D62B8DA0057F423 /* scanCodeBarCode.app */;
119 | productType = "com.apple.product-type.application";
120 | };
121 | /* End PBXNativeTarget section */
122 |
123 | /* Begin PBXProject section */
124 | 049164F91D62B8DA0057F423 /* Project object */ = {
125 | isa = PBXProject;
126 | attributes = {
127 | LastSwiftUpdateCheck = 0730;
128 | LastUpgradeCheck = 0730;
129 | ORGANIZATIONNAME = haohao;
130 | TargetAttributes = {
131 | 049165001D62B8DA0057F423 = {
132 | CreatedOnToolsVersion = 7.3;
133 | DevelopmentTeam = E4A85X89FN;
134 | LastSwiftMigration = 0800;
135 | };
136 | };
137 | };
138 | buildConfigurationList = 049164FC1D62B8DA0057F423 /* Build configuration list for PBXProject "scanCodeBarCode" */;
139 | compatibilityVersion = "Xcode 3.2";
140 | developmentRegion = English;
141 | hasScannedForEncodings = 0;
142 | knownRegions = (
143 | en,
144 | Base,
145 | );
146 | mainGroup = 049164F81D62B8DA0057F423;
147 | productRefGroup = 049165021D62B8DA0057F423 /* Products */;
148 | projectDirPath = "";
149 | projectRoot = "";
150 | targets = (
151 | 049165001D62B8DA0057F423 /* scanCodeBarCode */,
152 | );
153 | };
154 | /* End PBXProject section */
155 |
156 | /* Begin PBXResourcesBuildPhase section */
157 | 049164FF1D62B8DA0057F423 /* Resources */ = {
158 | isa = PBXResourcesBuildPhase;
159 | buildActionMask = 2147483647;
160 | files = (
161 | 0491650F1D62B8DA0057F423 /* LaunchScreen.storyboard in Resources */,
162 | 0491650C1D62B8DA0057F423 /* Assets.xcassets in Resources */,
163 | 049165211D62B8F50057F423 /* noticeMusic.wav in Resources */,
164 | 0491650A1D62B8DA0057F423 /* Main.storyboard in Resources */,
165 | );
166 | runOnlyForDeploymentPostprocessing = 0;
167 | };
168 | /* End PBXResourcesBuildPhase section */
169 |
170 | /* Begin PBXSourcesBuildPhase section */
171 | 049164FD1D62B8DA0057F423 /* Sources */ = {
172 | isa = PBXSourcesBuildPhase;
173 | buildActionMask = 2147483647;
174 | files = (
175 | 049165191D62B8EC0057F423 /* QRCodeViewController.swift in Sources */,
176 | 0491651A1D62B8EC0057F423 /* QRCodeReaderView.swift in Sources */,
177 | 049165071D62B8DA0057F423 /* ViewController.swift in Sources */,
178 | 049165051D62B8DA0057F423 /* AppDelegate.swift in Sources */,
179 | 0491651B1D62B8EC0057F423 /* MineQRCodeViewController.swift in Sources */,
180 | 0491651F1D62B8F50057F423 /* Category.swift in Sources */,
181 | 049165201D62B8F50057F423 /* Const.swift in Sources */,
182 | );
183 | runOnlyForDeploymentPostprocessing = 0;
184 | };
185 | /* End PBXSourcesBuildPhase section */
186 |
187 | /* Begin PBXVariantGroup section */
188 | 049165081D62B8DA0057F423 /* Main.storyboard */ = {
189 | isa = PBXVariantGroup;
190 | children = (
191 | 049165091D62B8DA0057F423 /* Base */,
192 | );
193 | name = Main.storyboard;
194 | sourceTree = "";
195 | };
196 | 0491650D1D62B8DA0057F423 /* LaunchScreen.storyboard */ = {
197 | isa = PBXVariantGroup;
198 | children = (
199 | 0491650E1D62B8DA0057F423 /* Base */,
200 | );
201 | name = LaunchScreen.storyboard;
202 | sourceTree = "";
203 | };
204 | /* End PBXVariantGroup section */
205 |
206 | /* Begin XCBuildConfiguration section */
207 | 049165111D62B8DA0057F423 /* Debug */ = {
208 | isa = XCBuildConfiguration;
209 | buildSettings = {
210 | ALWAYS_SEARCH_USER_PATHS = NO;
211 | CLANG_ANALYZER_NONNULL = YES;
212 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x";
213 | CLANG_CXX_LIBRARY = "libc++";
214 | CLANG_ENABLE_MODULES = YES;
215 | CLANG_ENABLE_OBJC_ARC = YES;
216 | CLANG_WARN_BOOL_CONVERSION = YES;
217 | CLANG_WARN_CONSTANT_CONVERSION = YES;
218 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
219 | CLANG_WARN_EMPTY_BODY = YES;
220 | CLANG_WARN_ENUM_CONVERSION = YES;
221 | CLANG_WARN_INT_CONVERSION = YES;
222 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
223 | CLANG_WARN_UNREACHABLE_CODE = YES;
224 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
225 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
226 | COPY_PHASE_STRIP = NO;
227 | DEBUG_INFORMATION_FORMAT = dwarf;
228 | ENABLE_STRICT_OBJC_MSGSEND = YES;
229 | ENABLE_TESTABILITY = YES;
230 | GCC_C_LANGUAGE_STANDARD = gnu99;
231 | GCC_DYNAMIC_NO_PIC = NO;
232 | GCC_NO_COMMON_BLOCKS = YES;
233 | GCC_OPTIMIZATION_LEVEL = 0;
234 | GCC_PREPROCESSOR_DEFINITIONS = (
235 | "DEBUG=1",
236 | "$(inherited)",
237 | );
238 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
239 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR;
240 | GCC_WARN_UNDECLARED_SELECTOR = YES;
241 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
242 | GCC_WARN_UNUSED_FUNCTION = YES;
243 | GCC_WARN_UNUSED_VARIABLE = YES;
244 | IPHONEOS_DEPLOYMENT_TARGET = 9.3;
245 | MTL_ENABLE_DEBUG_INFO = YES;
246 | ONLY_ACTIVE_ARCH = YES;
247 | SDKROOT = iphoneos;
248 | SWIFT_OPTIMIZATION_LEVEL = "-Onone";
249 | TARGETED_DEVICE_FAMILY = "1,2";
250 | };
251 | name = Debug;
252 | };
253 | 049165121D62B8DA0057F423 /* Release */ = {
254 | isa = XCBuildConfiguration;
255 | buildSettings = {
256 | ALWAYS_SEARCH_USER_PATHS = NO;
257 | CLANG_ANALYZER_NONNULL = YES;
258 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x";
259 | CLANG_CXX_LIBRARY = "libc++";
260 | CLANG_ENABLE_MODULES = YES;
261 | CLANG_ENABLE_OBJC_ARC = YES;
262 | CLANG_WARN_BOOL_CONVERSION = YES;
263 | CLANG_WARN_CONSTANT_CONVERSION = YES;
264 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
265 | CLANG_WARN_EMPTY_BODY = YES;
266 | CLANG_WARN_ENUM_CONVERSION = YES;
267 | CLANG_WARN_INT_CONVERSION = YES;
268 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
269 | CLANG_WARN_UNREACHABLE_CODE = YES;
270 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
271 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
272 | COPY_PHASE_STRIP = NO;
273 | DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
274 | ENABLE_NS_ASSERTIONS = NO;
275 | ENABLE_STRICT_OBJC_MSGSEND = YES;
276 | GCC_C_LANGUAGE_STANDARD = gnu99;
277 | GCC_NO_COMMON_BLOCKS = YES;
278 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
279 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR;
280 | GCC_WARN_UNDECLARED_SELECTOR = YES;
281 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
282 | GCC_WARN_UNUSED_FUNCTION = YES;
283 | GCC_WARN_UNUSED_VARIABLE = YES;
284 | IPHONEOS_DEPLOYMENT_TARGET = 9.3;
285 | MTL_ENABLE_DEBUG_INFO = NO;
286 | SDKROOT = iphoneos;
287 | TARGETED_DEVICE_FAMILY = "1,2";
288 | VALIDATE_PRODUCT = YES;
289 | };
290 | name = Release;
291 | };
292 | 049165141D62B8DA0057F423 /* Debug */ = {
293 | isa = XCBuildConfiguration;
294 | buildSettings = {
295 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
296 | CODE_SIGN_IDENTITY = "iPhone Developer";
297 | DEVELOPMENT_TEAM = E4A85X89FN;
298 | INFOPLIST_FILE = scanCodeBarCode/Info.plist;
299 | IPHONEOS_DEPLOYMENT_TARGET = 8.0;
300 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
301 | PRODUCT_BUNDLE_IDENTIFIER = com.lsf.scanCodeBarCode789;
302 | PRODUCT_NAME = "$(TARGET_NAME)";
303 | SWIFT_VERSION = 3.0;
304 | };
305 | name = Debug;
306 | };
307 | 049165151D62B8DA0057F423 /* Release */ = {
308 | isa = XCBuildConfiguration;
309 | buildSettings = {
310 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
311 | CODE_SIGN_IDENTITY = "iPhone Developer";
312 | DEVELOPMENT_TEAM = E4A85X89FN;
313 | INFOPLIST_FILE = scanCodeBarCode/Info.plist;
314 | IPHONEOS_DEPLOYMENT_TARGET = 8.0;
315 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
316 | PRODUCT_BUNDLE_IDENTIFIER = com.lsf.scanCodeBarCode789;
317 | PRODUCT_NAME = "$(TARGET_NAME)";
318 | SWIFT_VERSION = 3.0;
319 | };
320 | name = Release;
321 | };
322 | /* End XCBuildConfiguration section */
323 |
324 | /* Begin XCConfigurationList section */
325 | 049164FC1D62B8DA0057F423 /* Build configuration list for PBXProject "scanCodeBarCode" */ = {
326 | isa = XCConfigurationList;
327 | buildConfigurations = (
328 | 049165111D62B8DA0057F423 /* Debug */,
329 | 049165121D62B8DA0057F423 /* Release */,
330 | );
331 | defaultConfigurationIsVisible = 0;
332 | defaultConfigurationName = Release;
333 | };
334 | 049165131D62B8DA0057F423 /* Build configuration list for PBXNativeTarget "scanCodeBarCode" */ = {
335 | isa = XCConfigurationList;
336 | buildConfigurations = (
337 | 049165141D62B8DA0057F423 /* Debug */,
338 | 049165151D62B8DA0057F423 /* Release */,
339 | );
340 | defaultConfigurationIsVisible = 0;
341 | defaultConfigurationName = Release;
342 | };
343 | /* End XCConfigurationList section */
344 | };
345 | rootObject = 049164F91D62B8DA0057F423 /* Project object */;
346 | }
347 |
--------------------------------------------------------------------------------
/scanCodeBarCode.xcodeproj/project.xcworkspace/contents.xcworkspacedata:
--------------------------------------------------------------------------------
1 |
2 |
4 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/scanCodeBarCode.xcodeproj/project.xcworkspace/xcuserdata/ailishi.xcuserdatad/UserInterfaceState.xcuserstate:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zhanghongdou/QRCodeReaderView-Swift/ef069e0193081ff821440675804bad5a17933e0b/scanCodeBarCode.xcodeproj/project.xcworkspace/xcuserdata/ailishi.xcuserdatad/UserInterfaceState.xcuserstate
--------------------------------------------------------------------------------
/scanCodeBarCode.xcodeproj/xcuserdata/ailishi.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 |
--------------------------------------------------------------------------------
/scanCodeBarCode.xcodeproj/xcuserdata/ailishi.xcuserdatad/xcschemes/scanCodeBarCode.xcscheme:
--------------------------------------------------------------------------------
1 |
2 |
5 |
8 |
9 |
15 |
21 |
22 |
23 |
24 |
25 |
30 |
31 |
32 |
33 |
39 |
40 |
41 |
42 |
43 |
44 |
54 |
56 |
62 |
63 |
64 |
65 |
69 |
70 |
71 |
72 |
73 |
74 |
80 |
82 |
88 |
89 |
90 |
91 |
93 |
94 |
97 |
98 |
99 |
--------------------------------------------------------------------------------
/scanCodeBarCode.xcodeproj/xcuserdata/ailishi.xcuserdatad/xcschemes/xcschememanagement.plist:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | SchemeUserState
6 |
7 | scanCodeBarCode.xcscheme
8 |
9 | orderHint
10 | 0
11 |
12 |
13 | SuppressBuildableAutocreation
14 |
15 | 049165001D62B8DA0057F423
16 |
17 | primary
18 |
19 |
20 |
21 |
22 |
23 |
--------------------------------------------------------------------------------
/scanCodeBarCode/AppDelegate.swift:
--------------------------------------------------------------------------------
1 | //
2 | // AppDelegate.swift
3 | // scanCodeBarCode
4 | //
5 | // Created by haohao on 16/8/16.
6 | // Copyright © 2016年 haohao. All rights reserved.
7 | //
8 |
9 | import UIKit
10 |
11 | @UIApplicationMain
12 | class AppDelegate: UIResponder, UIApplicationDelegate {
13 |
14 | var window: UIWindow?
15 |
16 |
17 | func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
18 | // Override point for customization after application launch.
19 | return true
20 | }
21 |
22 | func applicationWillResignActive(_ application: UIApplication) {
23 | // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
24 | // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
25 | }
26 |
27 | func applicationDidEnterBackground(_ application: UIApplication) {
28 | // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
29 | // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
30 | }
31 |
32 | func applicationWillEnterForeground(_ application: UIApplication) {
33 | // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.
34 | NotificationCenter.default.post(name: Notification.Name(rawValue: "LAYERANIMATION"), object: nil)
35 | }
36 |
37 | func applicationDidBecomeActive(_ application: UIApplication) {
38 | // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
39 | }
40 |
41 | func applicationWillTerminate(_ application: UIApplication) {
42 | // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
43 | }
44 |
45 |
46 | }
47 |
48 |
--------------------------------------------------------------------------------
/scanCodeBarCode/Assets.xcassets/AppIcon.appiconset/Contents.json:
--------------------------------------------------------------------------------
1 | {
2 | "images" : [
3 | {
4 | "idiom" : "iphone",
5 | "size" : "29x29",
6 | "scale" : "2x"
7 | },
8 | {
9 | "idiom" : "iphone",
10 | "size" : "29x29",
11 | "scale" : "3x"
12 | },
13 | {
14 | "idiom" : "iphone",
15 | "size" : "40x40",
16 | "scale" : "2x"
17 | },
18 | {
19 | "idiom" : "iphone",
20 | "size" : "40x40",
21 | "scale" : "3x"
22 | },
23 | {
24 | "idiom" : "iphone",
25 | "size" : "60x60",
26 | "scale" : "2x"
27 | },
28 | {
29 | "idiom" : "iphone",
30 | "size" : "60x60",
31 | "scale" : "3x"
32 | },
33 | {
34 | "idiom" : "ipad",
35 | "size" : "29x29",
36 | "scale" : "1x"
37 | },
38 | {
39 | "idiom" : "ipad",
40 | "size" : "29x29",
41 | "scale" : "2x"
42 | },
43 | {
44 | "idiom" : "ipad",
45 | "size" : "40x40",
46 | "scale" : "1x"
47 | },
48 | {
49 | "idiom" : "ipad",
50 | "size" : "40x40",
51 | "scale" : "2x"
52 | },
53 | {
54 | "idiom" : "ipad",
55 | "size" : "76x76",
56 | "scale" : "1x"
57 | },
58 | {
59 | "idiom" : "ipad",
60 | "size" : "76x76",
61 | "scale" : "2x"
62 | },
63 | {
64 | "idiom" : "ipad",
65 | "size" : "83.5x83.5",
66 | "scale" : "2x"
67 | }
68 | ],
69 | "info" : {
70 | "version" : 1,
71 | "author" : "xcode"
72 | }
73 | }
--------------------------------------------------------------------------------
/scanCodeBarCode/Assets.xcassets/Contents.json:
--------------------------------------------------------------------------------
1 | {
2 | "info" : {
3 | "version" : 1,
4 | "author" : "xcode"
5 | }
6 | }
--------------------------------------------------------------------------------
/scanCodeBarCode/Assets.xcassets/QrDefault.imageset/Contents.json:
--------------------------------------------------------------------------------
1 | {
2 | "images" : [
3 | {
4 | "idiom" : "universal",
5 | "scale" : "1x"
6 | },
7 | {
8 | "idiom" : "universal",
9 | "filename" : "QrDefault@2x.jpg",
10 | "scale" : "2x"
11 | },
12 | {
13 | "idiom" : "universal",
14 | "scale" : "3x"
15 | }
16 | ],
17 | "info" : {
18 | "version" : 1,
19 | "author" : "xcode"
20 | }
21 | }
--------------------------------------------------------------------------------
/scanCodeBarCode/Assets.xcassets/QrDefault.imageset/QrDefault@2x.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zhanghongdou/QRCodeReaderView-Swift/ef069e0193081ff821440675804bad5a17933e0b/scanCodeBarCode/Assets.xcassets/QrDefault.imageset/QrDefault@2x.jpg
--------------------------------------------------------------------------------
/scanCodeBarCode/Assets.xcassets/ScanQR1_16x16_.imageset/Contents.json:
--------------------------------------------------------------------------------
1 | {
2 | "images" : [
3 | {
4 | "idiom" : "universal",
5 | "scale" : "1x"
6 | },
7 | {
8 | "idiom" : "universal",
9 | "filename" : "ScanQR1_16x16_@2x.png",
10 | "scale" : "2x"
11 | },
12 | {
13 | "idiom" : "universal",
14 | "filename" : "ScanQR1_16x16_@3x.png",
15 | "scale" : "3x"
16 | }
17 | ],
18 | "info" : {
19 | "version" : 1,
20 | "author" : "xcode"
21 | }
22 | }
--------------------------------------------------------------------------------
/scanCodeBarCode/Assets.xcassets/ScanQR1_16x16_.imageset/ScanQR1_16x16_@2x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zhanghongdou/QRCodeReaderView-Swift/ef069e0193081ff821440675804bad5a17933e0b/scanCodeBarCode/Assets.xcassets/ScanQR1_16x16_.imageset/ScanQR1_16x16_@2x.png
--------------------------------------------------------------------------------
/scanCodeBarCode/Assets.xcassets/ScanQR1_16x16_.imageset/ScanQR1_16x16_@3x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zhanghongdou/QRCodeReaderView-Swift/ef069e0193081ff821440675804bad5a17933e0b/scanCodeBarCode/Assets.xcassets/ScanQR1_16x16_.imageset/ScanQR1_16x16_@3x.png
--------------------------------------------------------------------------------
/scanCodeBarCode/Assets.xcassets/ScanQR2_16x16_.imageset/Contents.json:
--------------------------------------------------------------------------------
1 | {
2 | "images" : [
3 | {
4 | "idiom" : "universal",
5 | "scale" : "1x"
6 | },
7 | {
8 | "idiom" : "universal",
9 | "filename" : "ScanQR2_16x16_@2x.png",
10 | "scale" : "2x"
11 | },
12 | {
13 | "idiom" : "universal",
14 | "filename" : "ScanQR2_16x16_@3x.png",
15 | "scale" : "3x"
16 | }
17 | ],
18 | "info" : {
19 | "version" : 1,
20 | "author" : "xcode"
21 | }
22 | }
--------------------------------------------------------------------------------
/scanCodeBarCode/Assets.xcassets/ScanQR2_16x16_.imageset/ScanQR2_16x16_@2x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zhanghongdou/QRCodeReaderView-Swift/ef069e0193081ff821440675804bad5a17933e0b/scanCodeBarCode/Assets.xcassets/ScanQR2_16x16_.imageset/ScanQR2_16x16_@2x.png
--------------------------------------------------------------------------------
/scanCodeBarCode/Assets.xcassets/ScanQR2_16x16_.imageset/ScanQR2_16x16_@3x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zhanghongdou/QRCodeReaderView-Swift/ef069e0193081ff821440675804bad5a17933e0b/scanCodeBarCode/Assets.xcassets/ScanQR2_16x16_.imageset/ScanQR2_16x16_@3x.png
--------------------------------------------------------------------------------
/scanCodeBarCode/Assets.xcassets/ScanQR3_16x16_.imageset/Contents.json:
--------------------------------------------------------------------------------
1 | {
2 | "images" : [
3 | {
4 | "idiom" : "universal",
5 | "scale" : "1x"
6 | },
7 | {
8 | "idiom" : "universal",
9 | "filename" : "ScanQR3_16x16_@2x.png",
10 | "scale" : "2x"
11 | },
12 | {
13 | "idiom" : "universal",
14 | "filename" : "ScanQR3_16x16_@3x.png",
15 | "scale" : "3x"
16 | }
17 | ],
18 | "info" : {
19 | "version" : 1,
20 | "author" : "xcode"
21 | }
22 | }
--------------------------------------------------------------------------------
/scanCodeBarCode/Assets.xcassets/ScanQR3_16x16_.imageset/ScanQR3_16x16_@2x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zhanghongdou/QRCodeReaderView-Swift/ef069e0193081ff821440675804bad5a17933e0b/scanCodeBarCode/Assets.xcassets/ScanQR3_16x16_.imageset/ScanQR3_16x16_@2x.png
--------------------------------------------------------------------------------
/scanCodeBarCode/Assets.xcassets/ScanQR3_16x16_.imageset/ScanQR3_16x16_@3x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zhanghongdou/QRCodeReaderView-Swift/ef069e0193081ff821440675804bad5a17933e0b/scanCodeBarCode/Assets.xcassets/ScanQR3_16x16_.imageset/ScanQR3_16x16_@3x.png
--------------------------------------------------------------------------------
/scanCodeBarCode/Assets.xcassets/ScanQR4_16x16_.imageset/Contents.json:
--------------------------------------------------------------------------------
1 | {
2 | "images" : [
3 | {
4 | "idiom" : "universal",
5 | "scale" : "1x"
6 | },
7 | {
8 | "idiom" : "universal",
9 | "filename" : "ScanQR4_16x16_@2x.png",
10 | "scale" : "2x"
11 | },
12 | {
13 | "idiom" : "universal",
14 | "filename" : "ScanQR4_16x16_@3x.png",
15 | "scale" : "3x"
16 | }
17 | ],
18 | "info" : {
19 | "version" : 1,
20 | "author" : "xcode"
21 | }
22 | }
--------------------------------------------------------------------------------
/scanCodeBarCode/Assets.xcassets/ScanQR4_16x16_.imageset/ScanQR4_16x16_@2x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zhanghongdou/QRCodeReaderView-Swift/ef069e0193081ff821440675804bad5a17933e0b/scanCodeBarCode/Assets.xcassets/ScanQR4_16x16_.imageset/ScanQR4_16x16_@2x.png
--------------------------------------------------------------------------------
/scanCodeBarCode/Assets.xcassets/ScanQR4_16x16_.imageset/ScanQR4_16x16_@3x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zhanghongdou/QRCodeReaderView-Swift/ef069e0193081ff821440675804bad5a17933e0b/scanCodeBarCode/Assets.xcassets/ScanQR4_16x16_.imageset/ScanQR4_16x16_@3x.png
--------------------------------------------------------------------------------
/scanCodeBarCode/Assets.xcassets/ScanWord_35x35_.imageset/Contents.json:
--------------------------------------------------------------------------------
1 | {
2 | "images" : [
3 | {
4 | "idiom" : "universal",
5 | "scale" : "1x"
6 | },
7 | {
8 | "idiom" : "universal",
9 | "filename" : "ScanWord_35x35_@2x.png",
10 | "scale" : "2x"
11 | },
12 | {
13 | "idiom" : "universal",
14 | "filename" : "ScanWord_35x35_@3x.png",
15 | "scale" : "3x"
16 | }
17 | ],
18 | "info" : {
19 | "version" : 1,
20 | "author" : "xcode"
21 | }
22 | }
--------------------------------------------------------------------------------
/scanCodeBarCode/Assets.xcassets/ScanWord_35x35_.imageset/ScanWord_35x35_@2x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zhanghongdou/QRCodeReaderView-Swift/ef069e0193081ff821440675804bad5a17933e0b/scanCodeBarCode/Assets.xcassets/ScanWord_35x35_.imageset/ScanWord_35x35_@2x.png
--------------------------------------------------------------------------------
/scanCodeBarCode/Assets.xcassets/ScanWord_35x35_.imageset/ScanWord_35x35_@3x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zhanghongdou/QRCodeReaderView-Swift/ef069e0193081ff821440675804bad5a17933e0b/scanCodeBarCode/Assets.xcassets/ScanWord_35x35_.imageset/ScanWord_35x35_@3x.png
--------------------------------------------------------------------------------
/scanCodeBarCode/Assets.xcassets/ScanWord_HL_35x35_.imageset/Contents.json:
--------------------------------------------------------------------------------
1 | {
2 | "images" : [
3 | {
4 | "idiom" : "universal",
5 | "scale" : "1x"
6 | },
7 | {
8 | "idiom" : "universal",
9 | "filename" : "ScanWord_HL_35x35_@2x.png",
10 | "scale" : "2x"
11 | },
12 | {
13 | "idiom" : "universal",
14 | "filename" : "ScanWord_HL_35x35_@3x.png",
15 | "scale" : "3x"
16 | }
17 | ],
18 | "info" : {
19 | "version" : 1,
20 | "author" : "xcode"
21 | }
22 | }
--------------------------------------------------------------------------------
/scanCodeBarCode/Assets.xcassets/ScanWord_HL_35x35_.imageset/ScanWord_HL_35x35_@2x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zhanghongdou/QRCodeReaderView-Swift/ef069e0193081ff821440675804bad5a17933e0b/scanCodeBarCode/Assets.xcassets/ScanWord_HL_35x35_.imageset/ScanWord_HL_35x35_@2x.png
--------------------------------------------------------------------------------
/scanCodeBarCode/Assets.xcassets/ScanWord_HL_35x35_.imageset/ScanWord_HL_35x35_@3x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zhanghongdou/QRCodeReaderView-Swift/ef069e0193081ff821440675804bad5a17933e0b/scanCodeBarCode/Assets.xcassets/ScanWord_HL_35x35_.imageset/ScanWord_HL_35x35_@3x.png
--------------------------------------------------------------------------------
/scanCodeBarCode/Assets.xcassets/barcodeScan0.imageset/Contents.json:
--------------------------------------------------------------------------------
1 | {
2 | "images" : [
3 | {
4 | "idiom" : "universal",
5 | "scale" : "1x"
6 | },
7 | {
8 | "idiom" : "universal",
9 | "filename" : "barcodeScan0@2x.png",
10 | "scale" : "2x"
11 | },
12 | {
13 | "idiom" : "universal",
14 | "scale" : "3x"
15 | }
16 | ],
17 | "info" : {
18 | "version" : 1,
19 | "author" : "xcode"
20 | }
21 | }
--------------------------------------------------------------------------------
/scanCodeBarCode/Assets.xcassets/barcodeScan0.imageset/barcodeScan0@2x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zhanghongdou/QRCodeReaderView-Swift/ef069e0193081ff821440675804bad5a17933e0b/scanCodeBarCode/Assets.xcassets/barcodeScan0.imageset/barcodeScan0@2x.png
--------------------------------------------------------------------------------
/scanCodeBarCode/Assets.xcassets/barcodeScan1.imageset/Contents.json:
--------------------------------------------------------------------------------
1 | {
2 | "images" : [
3 | {
4 | "idiom" : "universal",
5 | "scale" : "1x"
6 | },
7 | {
8 | "idiom" : "universal",
9 | "filename" : "barcodeScan1@2x.png",
10 | "scale" : "2x"
11 | },
12 | {
13 | "idiom" : "universal",
14 | "scale" : "3x"
15 | }
16 | ],
17 | "info" : {
18 | "version" : 1,
19 | "author" : "xcode"
20 | }
21 | }
--------------------------------------------------------------------------------
/scanCodeBarCode/Assets.xcassets/barcodeScan1.imageset/barcodeScan1@2x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zhanghongdou/QRCodeReaderView-Swift/ef069e0193081ff821440675804bad5a17933e0b/scanCodeBarCode/Assets.xcassets/barcodeScan1.imageset/barcodeScan1@2x.png
--------------------------------------------------------------------------------
/scanCodeBarCode/Assets.xcassets/erweima_1.imageset/Contents.json:
--------------------------------------------------------------------------------
1 | {
2 | "images" : [
3 | {
4 | "idiom" : "universal",
5 | "scale" : "1x"
6 | },
7 | {
8 | "idiom" : "universal",
9 | "filename" : "erweima_1@2x.png",
10 | "scale" : "2x"
11 | },
12 | {
13 | "idiom" : "universal",
14 | "scale" : "3x"
15 | }
16 | ],
17 | "info" : {
18 | "version" : 1,
19 | "author" : "xcode"
20 | }
21 | }
--------------------------------------------------------------------------------
/scanCodeBarCode/Assets.xcassets/erweima_1.imageset/erweima_1@2x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zhanghongdou/QRCodeReaderView-Swift/ef069e0193081ff821440675804bad5a17933e0b/scanCodeBarCode/Assets.xcassets/erweima_1.imageset/erweima_1@2x.png
--------------------------------------------------------------------------------
/scanCodeBarCode/Assets.xcassets/line-1.imageset/Contents.json:
--------------------------------------------------------------------------------
1 | {
2 | "images" : [
3 | {
4 | "idiom" : "universal",
5 | "scale" : "1x"
6 | },
7 | {
8 | "idiom" : "universal",
9 | "filename" : "line@2x.png",
10 | "scale" : "2x"
11 | },
12 | {
13 | "idiom" : "universal",
14 | "scale" : "3x"
15 | }
16 | ],
17 | "info" : {
18 | "version" : 1,
19 | "author" : "xcode"
20 | }
21 | }
--------------------------------------------------------------------------------
/scanCodeBarCode/Assets.xcassets/line-1.imageset/line@2x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zhanghongdou/QRCodeReaderView-Swift/ef069e0193081ff821440675804bad5a17933e0b/scanCodeBarCode/Assets.xcassets/line-1.imageset/line@2x.png
--------------------------------------------------------------------------------
/scanCodeBarCode/Assets.xcassets/line.imageset/Contents.json:
--------------------------------------------------------------------------------
1 | {
2 | "images" : [
3 | {
4 | "idiom" : "universal",
5 | "filename" : "线.png",
6 | "scale" : "1x"
7 | },
8 | {
9 | "idiom" : "universal",
10 | "scale" : "2x"
11 | },
12 | {
13 | "idiom" : "universal",
14 | "scale" : "3x"
15 | }
16 | ],
17 | "info" : {
18 | "version" : 1,
19 | "author" : "xcode"
20 | }
21 | }
--------------------------------------------------------------------------------
/scanCodeBarCode/Assets.xcassets/line.imageset/线.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zhanghongdou/QRCodeReaderView-Swift/ef069e0193081ff821440675804bad5a17933e0b/scanCodeBarCode/Assets.xcassets/line.imageset/线.png
--------------------------------------------------------------------------------
/scanCodeBarCode/Assets.xcassets/qrcode_scan_btn_flash_off.imageset/Contents.json:
--------------------------------------------------------------------------------
1 | {
2 | "images" : [
3 | {
4 | "idiom" : "universal",
5 | "scale" : "1x"
6 | },
7 | {
8 | "idiom" : "universal",
9 | "filename" : "qrcode_scan_btn_flash_off@2x.png",
10 | "scale" : "2x"
11 | },
12 | {
13 | "idiom" : "universal",
14 | "scale" : "3x"
15 | }
16 | ],
17 | "info" : {
18 | "version" : 1,
19 | "author" : "xcode"
20 | }
21 | }
--------------------------------------------------------------------------------
/scanCodeBarCode/Assets.xcassets/qrcode_scan_btn_flash_off.imageset/qrcode_scan_btn_flash_off@2x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zhanghongdou/QRCodeReaderView-Swift/ef069e0193081ff821440675804bad5a17933e0b/scanCodeBarCode/Assets.xcassets/qrcode_scan_btn_flash_off.imageset/qrcode_scan_btn_flash_off@2x.png
--------------------------------------------------------------------------------
/scanCodeBarCode/Assets.xcassets/qrcode_scan_btn_flash_on.imageset/Contents.json:
--------------------------------------------------------------------------------
1 | {
2 | "images" : [
3 | {
4 | "idiom" : "universal",
5 | "scale" : "1x"
6 | },
7 | {
8 | "idiom" : "universal",
9 | "filename" : "qrcode_scan_btn_flash_on@2x.png",
10 | "scale" : "2x"
11 | },
12 | {
13 | "idiom" : "universal",
14 | "scale" : "3x"
15 | }
16 | ],
17 | "info" : {
18 | "version" : 1,
19 | "author" : "xcode"
20 | }
21 | }
--------------------------------------------------------------------------------
/scanCodeBarCode/Assets.xcassets/qrcode_scan_btn_flash_on.imageset/qrcode_scan_btn_flash_on@2x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zhanghongdou/QRCodeReaderView-Swift/ef069e0193081ff821440675804bad5a17933e0b/scanCodeBarCode/Assets.xcassets/qrcode_scan_btn_flash_on.imageset/qrcode_scan_btn_flash_on@2x.png
--------------------------------------------------------------------------------
/scanCodeBarCode/Assets.xcassets/qrcode_scan_btn_myqrcode_down.imageset/Contents.json:
--------------------------------------------------------------------------------
1 | {
2 | "images" : [
3 | {
4 | "idiom" : "universal",
5 | "scale" : "1x"
6 | },
7 | {
8 | "idiom" : "universal",
9 | "filename" : "qrcode_scan_btn_myqrcode_down@2x.png",
10 | "scale" : "2x"
11 | },
12 | {
13 | "idiom" : "universal",
14 | "scale" : "3x"
15 | }
16 | ],
17 | "info" : {
18 | "version" : 1,
19 | "author" : "xcode"
20 | }
21 | }
--------------------------------------------------------------------------------
/scanCodeBarCode/Assets.xcassets/qrcode_scan_btn_myqrcode_down.imageset/qrcode_scan_btn_myqrcode_down@2x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zhanghongdou/QRCodeReaderView-Swift/ef069e0193081ff821440675804bad5a17933e0b/scanCodeBarCode/Assets.xcassets/qrcode_scan_btn_myqrcode_down.imageset/qrcode_scan_btn_myqrcode_down@2x.png
--------------------------------------------------------------------------------
/scanCodeBarCode/Assets.xcassets/qrcode_scan_btn_myqrcode_nor.imageset/Contents.json:
--------------------------------------------------------------------------------
1 | {
2 | "images" : [
3 | {
4 | "idiom" : "universal",
5 | "scale" : "1x"
6 | },
7 | {
8 | "idiom" : "universal",
9 | "filename" : "qrcode_scan_btn_myqrcode_nor@2x.png",
10 | "scale" : "2x"
11 | },
12 | {
13 | "idiom" : "universal",
14 | "scale" : "3x"
15 | }
16 | ],
17 | "info" : {
18 | "version" : 1,
19 | "author" : "xcode"
20 | }
21 | }
--------------------------------------------------------------------------------
/scanCodeBarCode/Assets.xcassets/qrcode_scan_btn_myqrcode_nor.imageset/qrcode_scan_btn_myqrcode_nor@2x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zhanghongdou/QRCodeReaderView-Swift/ef069e0193081ff821440675804bad5a17933e0b/scanCodeBarCode/Assets.xcassets/qrcode_scan_btn_myqrcode_nor.imageset/qrcode_scan_btn_myqrcode_nor@2x.png
--------------------------------------------------------------------------------
/scanCodeBarCode/Assets.xcassets/qrcode_scan_full_net.imageset/Contents.json:
--------------------------------------------------------------------------------
1 | {
2 | "images" : [
3 | {
4 | "idiom" : "universal",
5 | "filename" : "qrcode_scan_full_net.png",
6 | "scale" : "1x"
7 | },
8 | {
9 | "idiom" : "universal",
10 | "scale" : "2x"
11 | },
12 | {
13 | "idiom" : "universal",
14 | "scale" : "3x"
15 | }
16 | ],
17 | "info" : {
18 | "version" : 1,
19 | "author" : "xcode"
20 | }
21 | }
--------------------------------------------------------------------------------
/scanCodeBarCode/Assets.xcassets/qrcode_scan_full_net.imageset/qrcode_scan_full_net.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zhanghongdou/QRCodeReaderView-Swift/ef069e0193081ff821440675804bad5a17933e0b/scanCodeBarCode/Assets.xcassets/qrcode_scan_full_net.imageset/qrcode_scan_full_net.png
--------------------------------------------------------------------------------
/scanCodeBarCode/Assets.xcassets/qrcode_scan_part_net.imageset/Contents.json:
--------------------------------------------------------------------------------
1 | {
2 | "images" : [
3 | {
4 | "idiom" : "universal",
5 | "filename" : "qrcode_scan_part_net.png",
6 | "scale" : "1x"
7 | },
8 | {
9 | "idiom" : "universal",
10 | "scale" : "2x"
11 | },
12 | {
13 | "idiom" : "universal",
14 | "scale" : "3x"
15 | }
16 | ],
17 | "info" : {
18 | "version" : 1,
19 | "author" : "xcode"
20 | }
21 | }
--------------------------------------------------------------------------------
/scanCodeBarCode/Assets.xcassets/qrcode_scan_part_net.imageset/qrcode_scan_part_net.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zhanghongdou/QRCodeReaderView-Swift/ef069e0193081ff821440675804bad5a17933e0b/scanCodeBarCode/Assets.xcassets/qrcode_scan_part_net.imageset/qrcode_scan_part_net.png
--------------------------------------------------------------------------------
/scanCodeBarCode/Assets.xcassets/scanScanBg1.imageset/Contents.json:
--------------------------------------------------------------------------------
1 | {
2 | "images" : [
3 | {
4 | "idiom" : "universal",
5 | "filename" : "scanScanBg1.png",
6 | "scale" : "1x"
7 | },
8 | {
9 | "idiom" : "universal",
10 | "scale" : "2x"
11 | },
12 | {
13 | "idiom" : "universal",
14 | "scale" : "3x"
15 | }
16 | ],
17 | "info" : {
18 | "version" : 1,
19 | "author" : "xcode"
20 | }
21 | }
--------------------------------------------------------------------------------
/scanCodeBarCode/Assets.xcassets/scanScanBg1.imageset/scanScanBg1.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zhanghongdou/QRCodeReaderView-Swift/ef069e0193081ff821440675804bad5a17933e0b/scanCodeBarCode/Assets.xcassets/scanScanBg1.imageset/scanScanBg1.png
--------------------------------------------------------------------------------
/scanCodeBarCode/Base.lproj/LaunchScreen.storyboard:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
--------------------------------------------------------------------------------
/scanCodeBarCode/Base.lproj/Main.storyboard:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 |
76 |
77 |
78 |
79 |
80 |
81 |
82 |
83 |
84 |
85 |
86 |
87 |
88 |
89 |
90 |
91 |
92 |
93 |
94 |
95 |
96 |
97 |
98 |
99 |
100 |
101 |
102 |
103 |
104 |
105 |
106 |
107 |
108 |
109 |
110 |
111 |
112 |
113 |
114 |
115 |
116 |
--------------------------------------------------------------------------------
/scanCodeBarCode/Category.swift:
--------------------------------------------------------------------------------
1 | //
2 | // Category.swift
3 |
4 | //
5 | // Created by haohao on 16/7/22.
6 | // Copyright © 2016年 haohao. All rights reserved.
7 | //
8 | //这个创建的swift file专门用来写扩展的
9 | import Foundation
10 | import UIKit
11 |
12 | //MARK: ------扩展button
13 | extension UIButton {
14 |
15 | enum HHButtonEdgeInsetsStyle: Int {
16 | case top = 1 //image在上,lebel在下
17 | case left //image在左,lebel在右
18 | case bottom //image在下,lebel在上
19 | case right //image在右,lebel在左
20 | }
21 |
22 | func layoutButtonWithEdgesInsetsStyleWithSpace(_ style : HHButtonEdgeInsetsStyle, space : CGFloat) {
23 | //首先得到imageView和titleLabel的宽高
24 | let imageWith = self.imageView?.frame.size.width
25 | let imageHeight = self.imageView?.frame.size.height
26 | var labelWith : CGFloat = 0
27 | var labelHeight : CGFloat = 0
28 | if kIOS8 == 1 {
29 | //由于ios8中titleLabel的size是0,用下面的这种设置
30 | labelWith = (self.titleLabel?.intrinsicContentSize.width)!
31 | labelHeight = (self.titleLabel?.intrinsicContentSize.height)!
32 | }else{
33 | labelWith = (self.titleLabel?.frame.size.width)!
34 | labelHeight = (self.titleLabel?.frame.size.height)!
35 | }
36 | var imageEdgeInsets = UIEdgeInsets.zero
37 | var labelEdgeInsets = UIEdgeInsets.zero
38 | //根据style和space得到imageEdgeInsets和labelEdgeInsets的值
39 | switch style {
40 | case .top:
41 | imageEdgeInsets = UIEdgeInsetsMake(-labelHeight - space / 2, 0, 0, -labelWith)
42 | labelEdgeInsets = UIEdgeInsetsMake(0, -imageWith!, -imageHeight! - space / 2, 0)
43 | case .left:
44 | imageEdgeInsets = UIEdgeInsetsMake(0, -space / 2, 0, space / 2)
45 | labelEdgeInsets = UIEdgeInsetsMake(0, space / 2, 0, -space / 2)
46 | case .bottom:
47 | imageEdgeInsets = UIEdgeInsetsMake(0, 0, -labelHeight - space / 2, -labelWith)
48 | labelEdgeInsets = UIEdgeInsetsMake(-imageHeight! - space / 2, -imageWith!, 0, 0)
49 | default:
50 | imageEdgeInsets = UIEdgeInsetsMake(0, labelWith + space / 2, 0, -labelWith - space / 2)
51 | labelEdgeInsets = UIEdgeInsetsMake(0, -imageWith! - space / 2, 0, imageWith! + space / 2)
52 | }
53 | self.titleEdgeInsets = labelEdgeInsets
54 | self.imageEdgeInsets = imageEdgeInsets
55 | }
56 | }
57 |
58 |
59 |
60 |
61 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 |
76 |
77 |
78 |
79 |
80 |
81 |
82 |
83 |
84 |
85 |
86 |
87 |
88 |
89 |
90 |
--------------------------------------------------------------------------------
/scanCodeBarCode/Const.swift:
--------------------------------------------------------------------------------
1 | //
2 | // Const.swift
3 |
4 | //
5 | // Created by haohao on 16/7/7.
6 | // Copyright © 2016年 haohao. All rights reserved.
7 | //
8 |
9 | import UIKit
10 | fileprivate func < (lhs: T?, rhs: T?) -> Bool {
11 | switch (lhs, rhs) {
12 | case let (l?, r?):
13 | return l < r
14 | case (nil, _?):
15 | return true
16 | default:
17 | return false
18 | }
19 | }
20 |
21 | fileprivate func >= (lhs: T?, rhs: T?) -> Bool {
22 | switch (lhs, rhs) {
23 | case let (l?, r?):
24 | return l >= r
25 | default:
26 | return !(lhs < rhs)
27 | }
28 | }
29 | //判断是真机还是模拟器的方法
30 | struct Platform {
31 | static let isSimulator: Bool = {
32 | var isSim = false
33 | #if arch(i386) || arch(x86_64)
34 | isSim = true
35 | #endif
36 | return isSim
37 | }()
38 | }
39 |
40 | //这样就是在建立宏
41 |
42 | let kIOS8 = Double(UIDevice.current.systemVersion) >= 8.0 ? 1 : 0
43 |
44 | let kScreenHeight = UIScreen.main.bounds.size.height
45 | let kScreenWidth = UIScreen.main.bounds.size.width
46 |
47 |
--------------------------------------------------------------------------------
/scanCodeBarCode/Info.plist:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | CFBundleAllowMixedLocalizations
6 |
7 | CFBundleDevelopmentRegion
8 | en
9 | CFBundleDisplayName
10 | scanCodeBarCode
11 | CFBundleExecutable
12 | $(EXECUTABLE_NAME)
13 | CFBundleIdentifier
14 | $(PRODUCT_BUNDLE_IDENTIFIER)
15 | CFBundleInfoDictionaryVersion
16 | 6.0
17 | CFBundleName
18 | $(PRODUCT_NAME)
19 | CFBundlePackageType
20 | APPL
21 | CFBundleShortVersionString
22 | 1.0
23 | CFBundleSignature
24 | ????
25 | CFBundleVersion
26 | 1
27 | LSRequiresIPhoneOS
28 |
29 | NSCameraUsageDescription
30 | $(PRODUCT_NAME) camera use
31 | NSPhotoLibraryUsageDescription
32 | $(PRODUCT_NAME) photo use
33 | UILaunchStoryboardName
34 | LaunchScreen
35 | UIMainStoryboardFile
36 | Main
37 | UIRequiredDeviceCapabilities
38 |
39 | armv7
40 |
41 | UISupportedInterfaceOrientations
42 |
43 | UIInterfaceOrientationPortrait
44 |
45 | UISupportedInterfaceOrientations~ipad
46 |
47 | UIInterfaceOrientationPortrait
48 | UIInterfaceOrientationPortraitUpsideDown
49 | UIInterfaceOrientationLandscapeLeft
50 | UIInterfaceOrientationLandscapeRight
51 |
52 |
53 |
54 |
--------------------------------------------------------------------------------
/scanCodeBarCode/MineQRCodeViewController.swift:
--------------------------------------------------------------------------------
1 | //
2 | // MineQRCodeViewController.swift
3 | // QRCodeScan
4 | //
5 | // Created by haohao on 16/8/12.
6 | // Copyright © 2016年 haohao. All rights reserved.
7 | //
8 |
9 | import UIKit
10 |
11 | class MineQRCodeViewController: UIViewController {
12 |
13 | @IBOutlet weak var codeImageView: UIImageView!
14 | override func viewDidLoad() {
15 | super.viewDidLoad()
16 | // Do any additional setup after loading the view.
17 | self.codeImageView.image = self.creatQRCodeOfMine(codeUrl: "www.baidu.com", width: 200, height: 200, baseColor: UIColor.white, codeColor: UIColor.black)
18 |
19 | //设置中心的图像
20 | self.setCenterImageView(UIImage(named: "QrDefault"))
21 | }
22 |
23 | func creatQRCodeOfMine(codeUrl : String, width : CGFloat, height : CGFloat, baseColor : UIColor, codeColor : UIColor) -> UIImage {
24 |
25 | let data = codeUrl.data(using: String.Encoding.utf8)
26 | //系统自带的
27 | // CIAztecCodeGenerator
28 | // CICode128BarcodeGenerator
29 | // CIPDF417BarcodeGenerator
30 | // CIQRCodeGenerator
31 | //实例化二维码滤镜
32 | let filter = CIFilter(name: "CIQRCodeGenerator")
33 | // //恢复滤镜的默认属性
34 | // filter?.setDefaults()
35 | //通过KVO设置滤镜inputMessage数据
36 | filter?.setValue(data, forKey: "inputMessage")
37 | filter?.setValue("H", forKey: "inputCorrectionLevel")
38 |
39 | //上色(设置二维码的底色和码色,input0是码色,input1是底色)
40 | let colorFilter = CIFilter(name: "CIFalseColor", withInputParameters: ["inputImage":filter!.outputImage!,"inputColor0":CIColor(cgColor: codeColor.cgColor),"inputColor1":CIColor(cgColor: baseColor.cgColor)])
41 |
42 |
43 | //获得滤镜输出的图像
44 | let qrCodeImage = colorFilter!.outputImage
45 | let scaleX = width / (qrCodeImage?.extent.size.width)!
46 | let scaleY = height / (qrCodeImage?.extent.size.height)!
47 | let transformedImage = qrCodeImage?.applying(CGAffineTransform.identity.scaledBy(x: scaleX, y: scaleY))
48 | return UIImage.init(ciImage: transformedImage!)
49 | }
50 |
51 | func setCenterImageView(_ centerImage : UIImage?) {
52 | let centerImageView = UIImageView()
53 | centerImageView.center = CGPoint(x: self.codeImageView.frame.size.width / 2, y: self.codeImageView.frame.size.height / 2)
54 | centerImageView.bounds = CGRect(x: 0, y: 0, width: 30, height: 30)
55 | centerImageView.layer.cornerRadius = 15
56 | self.codeImageView.addSubview(centerImageView)
57 | if centerImage != nil {
58 | centerImageView.image = centerImage
59 | }else{
60 | centerImageView.image = UIImage(named: "QrDefault")
61 | }
62 | }
63 |
64 | override func didReceiveMemoryWarning() {
65 | super.didReceiveMemoryWarning()
66 | // Dispose of any resources that can be recreated.
67 | }
68 |
69 |
70 |
71 | /*
72 | // MARK: - Navigation
73 |
74 | // In a storyboard-based application, you will often want to do a little preparation before navigation
75 | override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
76 | // Get the new view controller using segue.destinationViewController.
77 | // Pass the selected object to the new view controller.
78 | }
79 | */
80 |
81 | }
82 |
--------------------------------------------------------------------------------
/scanCodeBarCode/QRCodeReaderView.swift:
--------------------------------------------------------------------------------
1 | //
2 | // QRCodeReaderView.swift
3 | // hunbian
4 | //
5 | // Created by haohao on 16/8/11.
6 | // Copyright © 2016年 haohao. All rights reserved.
7 | //
8 |
9 | import UIKit
10 | import AVFoundation
11 | //进入我的二维码的闭包
12 | typealias putInMyQRCodeController = () -> Void
13 | //处理扫描结果的delegate
14 | protocol HandleTheResultDelegate : class {
15 | func handelTheResult(_ metadataObjectString: String) -> Void
16 | }
17 | extension HandleTheResultDelegate {
18 | func handelTheResult(_ metadataObjectString: String) -> Void {}
19 | }
20 | //enum DAOError: ErrorType {
21 | // case NoData
22 | // case NullKey
23 | //}
24 |
25 | //设置扫描的结构体
26 | enum ScanQRCodeType: Int {
27 | case qrCode = 1
28 | case barCode
29 | }
30 |
31 | class QRCodeReaderView: UIView, AVCaptureMetadataOutputObjectsDelegate{
32 | let device:AVCaptureDevice? = AVCaptureDevice.defaultDevice(withMediaType: AVMediaTypeVideo);
33 | var puinMyCodeController : putInMyQRCodeController?
34 | var captureSession : AVCaptureSession?
35 | var videoPreviewLayer : AVCaptureVideoPreviewLayer?
36 | var lastResult = Bool()
37 | var isAnmotion = false
38 | var lineImageView : UIImageView?
39 | var delegate : HandleTheResultDelegate?
40 | var input : AVCaptureDeviceInput?
41 | //创建输出流
42 | var outPut : AVCaptureMetadataOutput!
43 | //扫描的类型
44 | var scanType : ScanQRCodeType?
45 | let defaultBothSideWidth : CGFloat = 60
46 |
47 | //设置四周的View
48 | var topView : UIView?
49 | var leftView : UIView?
50 | var rightView : UIView?
51 | var bottomView : UIView?
52 |
53 | var leftQRCodeBtn : UIButton!
54 | var barCodeBtn : UIButton!
55 | var btnBottomView : UIView!
56 |
57 | //扫描区域的相框
58 | var leftTopLayer = CAShapeLayer()
59 | var rightTopLayer = CAShapeLayer()
60 | var leftBottomLayer = CAShapeLayer()
61 | var rightBottomLayer = CAShapeLayer()
62 |
63 | //条形码扫描的时候的红线
64 | var redLine : UIView?
65 |
66 |
67 | override init(frame: CGRect) {
68 | super.init(frame: frame)
69 | NotificationCenter.default.addObserver(self, selector: #selector(QRCodeReaderView.creatDrawLine), name: NSNotification.Name(rawValue: "LAYERANIMATION"), object: nil)
70 | self.creatDataSource()
71 | self.setBottomBtnView()
72 | //条形码扫描的时候添加中间的红线
73 | self.addRedLineWithBarCodeScan()
74 | }
75 |
76 |
77 | override func draw(_ rect: CGRect) {
78 | var scanZoneSize = CGSize(width: kScreenWidth - self.defaultBothSideWidth * 2, height: kScreenWidth - self.defaultBothSideWidth * 2)
79 | if scanType == .barCode {
80 | scanZoneSize = CGSize(width: kScreenWidth - self.defaultBothSideWidth * 2, height: 150)
81 | }
82 | //获取扫描区域的坐标
83 | let x = self.defaultBothSideWidth
84 | let y = kScreenHeight / 2 - scanZoneSize.height / 2
85 | let scanRect = CGRect(x: x, y: y, width: scanZoneSize.width, height: scanZoneSize.height)
86 | self.creatOtherView(scanRect)
87 | //设置扫描区域
88 | let rect = self.creatScanZone(scanRect)
89 | outPut.rectOfInterest = CGRect(x: rect.origin.x, y: rect.origin.y, width: rect.size.width, height: rect.size.height)
90 |
91 | //设置扫描区域的线框
92 | self.setScanZoneLineBorder(scanRect)
93 |
94 |
95 | }
96 |
97 | //MARK: ---条形码扫描的时候添加中间的红线
98 | func addRedLineWithBarCodeScan() {
99 | if self.redLine == nil {
100 | self.redLine = UIView()
101 | self.redLine?.center = self.center
102 | self.redLine?.bounds = CGRect(x: 0, y: 0, width: kScreenWidth - 60 * 2 - 20, height: 1.5)
103 | self.redLine?.backgroundColor = UIColor.red
104 | self.addSubview(self.redLine!)
105 | self.redLine?.isHidden = true
106 | }
107 | }
108 |
109 | //MARK: ---设置扫描区域的线框
110 | func setScanZoneLineBorder(_ scanRect : CGRect) {
111 | leftTopLayer.removeFromSuperlayer()
112 | rightTopLayer.removeFromSuperlayer()
113 | leftBottomLayer.removeFromSuperlayer()
114 | rightBottomLayer.removeFromSuperlayer()
115 | //左上角的框
116 | let leftTopBezierPath = UIBezierPath()
117 | leftTopBezierPath.move(to: CGPoint(x: scanRect.minX + 15, y: scanRect.minY - 2))
118 | leftTopBezierPath.addLine(to: CGPoint(x: scanRect.minX - 2, y: scanRect.minY - 2))
119 | leftTopBezierPath.addLine(to: CGPoint(x: scanRect.minX - 2, y: scanRect.minY + 15))
120 | leftTopLayer.path = leftTopBezierPath.cgPath
121 | leftTopLayer.lineWidth = 4
122 | leftTopLayer.strokeColor = UIColor.green.cgColor
123 | leftTopLayer.fillColor = UIColor.clear.cgColor
124 | self.layer.addSublayer(leftTopLayer)
125 |
126 | //右上角的框
127 | let rightTopBezierPath = UIBezierPath()
128 | rightTopBezierPath.move(to: CGPoint(x: scanRect.maxX - 15, y: scanRect.minY - 2))
129 | rightTopBezierPath.addLine(to: CGPoint(x: scanRect.maxX + 2, y: scanRect.minY - 2))
130 | rightTopBezierPath.addLine(to: CGPoint(x: scanRect.maxX + 2, y: scanRect.minY + 15))
131 | rightTopLayer.path = rightTopBezierPath.cgPath
132 | rightTopLayer.lineWidth = 4
133 | rightTopLayer.strokeColor = UIColor.green.cgColor
134 | rightTopLayer.fillColor = UIColor.clear.cgColor
135 | self.layer.addSublayer(rightTopLayer)
136 |
137 | //左下角
138 | let leftBottomBezierPath = UIBezierPath()
139 | leftBottomBezierPath.move(to: CGPoint(x: scanRect.minX + 15, y: scanRect.maxY + 2))
140 | leftBottomBezierPath.addLine(to: CGPoint(x: scanRect.minX - 2, y: scanRect.maxY + 2))
141 | leftBottomBezierPath.addLine(to: CGPoint(x: scanRect.minX - 2, y: scanRect.maxY - 15))
142 | leftBottomLayer.path = leftBottomBezierPath.cgPath
143 | leftBottomLayer.lineWidth = 4
144 | leftBottomLayer.strokeColor = UIColor.green.cgColor
145 | leftBottomLayer.fillColor = UIColor.clear.cgColor
146 | self.layer.addSublayer(leftBottomLayer)
147 |
148 |
149 | //右下角
150 | let rightBottomBezierPath = UIBezierPath()
151 | rightBottomBezierPath.move(to: CGPoint(x: scanRect.maxX + 2, y: scanRect.maxY - 15))
152 | rightBottomBezierPath.addLine(to: CGPoint(x: scanRect.maxX + 2, y: scanRect.maxY + 2))
153 | rightBottomBezierPath.addLine(to: CGPoint(x: scanRect.maxX - 15, y: scanRect.maxY + 2))
154 | rightBottomLayer.path = rightBottomBezierPath.cgPath
155 | rightBottomLayer.lineWidth = 4
156 | rightBottomLayer.strokeColor = UIColor.green.cgColor
157 | rightBottomLayer.fillColor = UIColor.clear.cgColor
158 | self.layer.addSublayer(rightBottomLayer)
159 |
160 | }
161 |
162 | //MARK: ---创建扫描需要的条件
163 | func creatDataSource() {
164 | self.captureSession = AVCaptureSession()
165 | self.captureSession?.sessionPreset = AVCaptureSessionPresetHigh
166 | //创建输入流
167 | do {
168 | input = try AVCaptureDeviceInput(device: device)
169 |
170 | } catch let error as NSError{
171 | print("AVCaptureDeviceInput(): \(error)")
172 | }
173 | if input != nil {
174 | self.captureSession?.addInput(input)
175 | }
176 |
177 | outPut = AVCaptureMetadataOutput()
178 |
179 | if device == nil {
180 | return
181 | }
182 | //参数设置
183 | outPut.setMetadataObjectsDelegate(self, queue: DispatchQueue.main)
184 | self.captureSession?.addOutput(outPut)
185 |
186 | //设置元数据类型(二维码和条形码都支持)
187 | outPut.metadataObjectTypes = [AVMetadataObjectTypeQRCode,AVMetadataObjectTypeEAN13Code, AVMetadataObjectTypeEAN8Code, AVMetadataObjectTypeCode128Code]
188 |
189 | //设置采集的质量
190 | self.captureSession?.sessionPreset = AVCaptureSessionPresetHigh
191 | self.videoPreviewLayer = AVCaptureVideoPreviewLayer.init(session: self.captureSession)
192 |
193 | //layer进行裁剪
194 | self.videoPreviewLayer?.videoGravity = AVLayerVideoGravityResizeAspectFill
195 | self.videoPreviewLayer?.frame = self.layer.bounds
196 | self.layer.insertSublayer(self.videoPreviewLayer!, at: 0)
197 |
198 | //设置聚焦(不是说所有的设备都支持,所以需要判断)
199 | if device!.isFocusPointOfInterestSupported && device!.isFocusModeSupported(AVCaptureFocusMode.continuousAutoFocus) {
200 | do {
201 | try self.input?.device.lockForConfiguration()
202 | self.input?.device.focusMode = AVCaptureFocusMode.continuousAutoFocus
203 | self.input?.device.unlockForConfiguration()
204 | }catch let error as NSError {
205 | print("device.lockForConfiguration(): \(error)")
206 | }
207 | }
208 |
209 | }
210 |
211 | //MARK: ---设置扫描区域的边框
212 | func setScanZoneBorder(imageViewScan : UIImageView) {
213 | let leftTopImageView = UIImageView.init(frame: CGRect(x: 0, y: 0, width: 20, height: 20))
214 | leftTopImageView.image = UIImage(named: "ScanQR1_16x16_")
215 | leftTopImageView.backgroundColor = UIColor.clear
216 | imageViewScan.addSubview(leftTopImageView)
217 |
218 | let rightopImageView = UIImageView.init(frame: CGRect(x: imageViewScan.frame.width - 20, y: 0, width: 20, height: 20))
219 | rightopImageView.image = UIImage(named: "ScanQR2_16x16_")
220 | rightopImageView.backgroundColor = UIColor.clear
221 | imageViewScan.addSubview(rightopImageView)
222 |
223 |
224 | let righBottomImageView = UIImageView.init(frame: CGRect(x: imageViewScan.frame.width - 20, y: imageViewScan.frame.height - 20, width: 20, height: 20))
225 | righBottomImageView.image = UIImage(named: "ScanQR4_16x16_")
226 | righBottomImageView.backgroundColor = UIColor.clear
227 | imageViewScan.addSubview(righBottomImageView)
228 |
229 | let leftBottomImageView = UIImageView.init(frame: CGRect(x: 0, y: imageViewScan.frame.height - 20, width: 20, height: 20))
230 | leftBottomImageView.image = UIImage(named: "ScanQR3_16x16_")
231 | leftBottomImageView.backgroundColor = UIColor.clear
232 | imageViewScan.addSubview(leftBottomImageView)
233 | }
234 |
235 | //MARK: ---扫描线
236 | func creatDrawLine() {
237 |
238 | let rect = CGRect(x: 60 + 10, y: (kScreenHeight - (kScreenWidth - 60 * 2)) / 2, width: kScreenWidth - 60 * 2 - 20, height: 2)
239 | if self.lineImageView == nil {
240 | self.lineImageView = UIImageView.init(frame: rect)
241 | self.lineImageView?.image = UIImage(named: "line-1")
242 | self.addSubview(self.lineImageView!)
243 | }
244 |
245 | let transitionAnimation = CABasicAnimation.init(keyPath: "position")
246 | transitionAnimation.fromValue = NSValue.init(cgPoint: CGPoint(x: 60 + (kScreenWidth - 60 * 2) / 2, y: (kScreenHeight - (kScreenWidth - 60 * 2)) / 2))
247 | transitionAnimation.toValue = NSValue.init(cgPoint: CGPoint( x: 60 + (kScreenWidth - 60 * 2) / 2, y: kScreenHeight / 2 + (kScreenWidth - 60 * 2) / 2))
248 | transitionAnimation.duration = 1.8
249 | transitionAnimation.repeatCount = 999
250 | transitionAnimation.autoreverses = true
251 | self.lineImageView?.layer.add(transitionAnimation, forKey: "transitionAnimation")
252 | }
253 |
254 | //MARK: ---暂停动画的方法
255 | func stopLineAnimation() {
256 | let pauseTime = self.lineImageView?.layer.convertTime(CACurrentMediaTime(), from: nil)
257 | self.lineImageView?.layer.speed = 0
258 | self.lineImageView?.layer.timeOffset = pauseTime!
259 | }
260 | //MARK: ---继续动画的方法
261 | func startLineAnimation() {
262 | let pauseTime = self.lineImageView?.layer.timeOffset
263 | self.lineImageView?.layer.speed = 1
264 | self.lineImageView?.layer.beginTime = 0
265 | self.lineImageView?.layer.timeOffset = 0
266 | let timeSincePause = (self.lineImageView?.layer.convertTime(CACurrentMediaTime(), from: nil))! - pauseTime!
267 | self.lineImageView?.layer.beginTime = timeSincePause
268 |
269 | }
270 |
271 | func creatOtherView(_ scanRect : CGRect) {
272 | let allAlpha : CGFloat = 0.5
273 |
274 | //最上部的View
275 | if topView != nil {
276 | topView?.removeFromSuperview()
277 | topView = nil
278 | }
279 | topView = UIView.init(frame: CGRect(x: 0, y: 0, width: kScreenWidth, height: scanRect.origin.y))
280 | topView!.alpha = allAlpha
281 | topView!.backgroundColor = UIColor.black
282 | self.addSubview(topView!)
283 |
284 | //左侧的View
285 | if leftView != nil {
286 | leftView?.removeFromSuperview()
287 | leftView = nil
288 | }
289 | leftView = UIView.init(frame: CGRect(x: 0, y: scanRect.origin.y, width: self.defaultBothSideWidth, height: scanRect.size.height))
290 | leftView!.backgroundColor = UIColor.black
291 | leftView!.alpha = allAlpha
292 | self.addSubview(leftView!)
293 |
294 |
295 | //右侧的View
296 | if rightView != nil {
297 | rightView?.removeFromSuperview()
298 | rightView = nil
299 | }
300 | rightView = UIView.init(frame: CGRect(x: scanRect.maxX, y: scanRect.origin.y, width: self.defaultBothSideWidth, height: scanRect.size.height))
301 | rightView!.backgroundColor = UIColor.black
302 | rightView!.alpha = allAlpha
303 | self.addSubview(rightView!)
304 |
305 |
306 | //底部的View
307 | if bottomView != nil {
308 | bottomView?.removeFromSuperview()
309 | bottomView = nil
310 | }
311 | bottomView = UIView.init(frame: CGRect(x: 0,y: scanRect.maxY, width: kScreenWidth, height: kScreenHeight - scanRect.maxY - 100))
312 | bottomView!.backgroundColor = UIColor.black
313 | bottomView!.alpha = allAlpha
314 | self.addSubview(bottomView!)
315 |
316 | let detailLabel = UILabel.init(frame: CGRect(x: 0, y: 10, width: kScreenWidth, height: 20))
317 | detailLabel.backgroundColor = UIColor.clear
318 | detailLabel.textColor = UIColor.white
319 | if self.scanType == .barCode {
320 | detailLabel.text = "将条形码放入框内,即可自动扫描"
321 | }else{
322 | detailLabel.text = "将二维码放入框内,即可自动扫描"
323 | }
324 |
325 |
326 | detailLabel.font = UIFont.systemFont(ofSize: 16)
327 | detailLabel.textAlignment = .center
328 | bottomView!.addSubview(detailLabel)
329 |
330 | //我的二维码
331 | let mineBtn = UIButton.init(frame: CGRect(x: (kScreenWidth - 150) / 2, y: 40, width: 150, height: 40))
332 | mineBtn.titleLabel?.font = UIFont.systemFont(ofSize: 16)
333 | mineBtn.setTitle("我的二维码", for: UIControlState())
334 | mineBtn.setTitleColor(UIColor.white, for: UIControlState())
335 | mineBtn.setImage(UIImage.init(named: "erweima_1"), for: UIControlState())
336 | mineBtn.layer.cornerRadius = 20
337 | mineBtn.backgroundColor = UIColor.black
338 | mineBtn.layoutButtonWithEdgesInsetsStyleWithSpace(.left, space: 10)
339 | mineBtn.addTarget(self, action: #selector(QRCodeReaderView.pushInMineQRCode), for: .touchUpInside)
340 | bottomView!.addSubview(mineBtn)
341 | if self.scanType == .barCode {
342 | mineBtn.isHidden = true
343 | }else{
344 | mineBtn.isHidden = false
345 | }
346 | }
347 |
348 |
349 | //MARK: ---设置底部的按钮
350 | func setBottomBtnView() {
351 | //设置底部的按钮View
352 | let btnBottomViewHeight : CGFloat = 100
353 | btnBottomView = UIView.init(frame: CGRect(x: 0, y: kScreenHeight - btnBottomViewHeight, width: kScreenWidth, height: btnBottomViewHeight))
354 | btnBottomView.backgroundColor = UIColor.black
355 | btnBottomView.alpha = 0.8
356 | self.addSubview(btnBottomView)
357 | self.bringSubview(toFront: btnBottomView)
358 |
359 | //二维码
360 | let width = kScreenWidth / 3
361 | leftQRCodeBtn = UIButton.init(frame: CGRect(x: 0, y: 0, width: width, height: btnBottomViewHeight))
362 | leftQRCodeBtn.setImage(UIImage(named: "qrcode_scan_btn_myqrcode_down"), for: .selected)
363 | leftQRCodeBtn.setImage(UIImage(named: "qrcode_scan_btn_myqrcode_nor"), for: UIControlState())
364 | leftQRCodeBtn.setTitle("二维码", for: UIControlState())
365 | leftQRCodeBtn.layoutButtonWithEdgesInsetsStyleWithSpace(.top, space: 10)
366 | leftQRCodeBtn.titleLabel?.font = UIFont.systemFont(ofSize: 14)
367 | leftQRCodeBtn.addTarget(self, action: #selector(QRCodeReaderView.scanQRCode(_:)), for: .touchUpInside)
368 | btnBottomView.addSubview(leftQRCodeBtn)
369 | leftQRCodeBtn.isSelected = true
370 | //开灯
371 | let lightBtn = UIButton.init(frame: CGRect(x: width, y: 0, width: width, height: btnBottomViewHeight))
372 | lightBtn.setImage(UIImage(named: "qrcode_scan_btn_flash_on"), for: .selected)
373 | lightBtn.setImage(UIImage(named: "qrcode_scan_btn_flash_off"), for: UIControlState())
374 | lightBtn.setTitle("开灯", for: UIControlState())
375 | lightBtn.setTitle("关灯", for: .selected)
376 | lightBtn.layoutButtonWithEdgesInsetsStyleWithSpace(.top, space: 10)
377 | lightBtn.titleLabel?.font = UIFont.systemFont(ofSize: 14)
378 | lightBtn.addTarget(self, action: #selector(QRCodeReaderView.turnOnOrOffWigthLight(_:)), for: .touchUpInside)
379 | btnBottomView.addSubview(lightBtn)
380 |
381 | //条形码
382 | barCodeBtn = UIButton.init(frame: CGRect(x: width * 2, y: 0, width: width, height: btnBottomViewHeight))
383 | barCodeBtn.setImage(UIImage(named: "barcodeScan0"), for: .selected)
384 | barCodeBtn.setImage(UIImage(named: "barcodeScan1"), for: UIControlState())
385 | barCodeBtn.setTitle("条形码", for: UIControlState())
386 | barCodeBtn.layoutButtonWithEdgesInsetsStyleWithSpace(.top, space: 10)
387 | barCodeBtn.addTarget(self, action: #selector(QRCodeReaderView.scanBarCode(_:)), for: .touchUpInside)
388 | barCodeBtn.titleLabel?.font = UIFont.systemFont(ofSize: 14)
389 | btnBottomView.addSubview(barCodeBtn)
390 | }
391 |
392 | //MARK: ---点击开灯按钮的事件
393 | func turnOnOrOffWigthLight(_ sender : UIButton) {
394 | sender.isSelected = sender.isSelected ? false : true
395 | self.theLightIsON(sender.isSelected)
396 | }
397 | //MARK: ---开灯或者关灯
398 | func theLightIsON(_ turnLight : Bool){
399 | if device != nil && device!.hasTorch {
400 | do{
401 | try input?.device.lockForConfiguration()
402 | input?.device.torchMode = turnLight ? AVCaptureTorchMode.on : AVCaptureTorchMode.off
403 | input?.device.unlockForConfiguration()
404 | }catch let error as NSError {
405 | print("device.lockForConfiguration(): \(error)")
406 | }
407 | }
408 | }
409 |
410 | //MARK: ---扫描二维码
411 | func scanQRCode(_ sender : UIButton) {
412 | if sender.isSelected {
413 | return
414 | }
415 | leftQRCodeBtn.isSelected = true
416 | barCodeBtn.isSelected = false
417 | self.scanType = .qrCode
418 | self.setNeedsDisplay()
419 | self.lineImageView?.isHidden = false
420 | self.redLine?.isHidden = true
421 | self.start()
422 | self.startLineAnimation()
423 | }
424 |
425 | //MARK: ---扫描条形码
426 | func scanBarCode(_ sender : UIButton) {
427 | if sender.isSelected {
428 | return
429 | }
430 | leftQRCodeBtn.isSelected = false
431 | barCodeBtn.isSelected = true
432 | self.scanType = .barCode
433 | self.setNeedsDisplay()
434 | self.lineImageView?.isHidden = true
435 | self.redLine?.isHidden = false
436 | self.start()
437 | }
438 |
439 | //MARK: ---进入我的二维码试图控制器
440 | func pushInMineQRCode() {
441 | if self.puinMyCodeController != nil {
442 | self.puinMyCodeController!()
443 | }
444 | }
445 | //MARK: ---创建扫描区域
446 | func creatScanZone(_ rect: CGRect) -> CGRect {
447 | var x = CGFloat()
448 | var y = CGFloat()
449 | var width = CGFloat()
450 | var height = CGFloat()
451 | x = (self.frame.height - rect.height) / 2 / self.frame.height
452 | y = (self.frame.width - rect.width) / 2 / self.frame.width
453 | width = rect.height / self.frame.height
454 | height = rect.width / self.frame.width
455 | return CGRect(x: x, y: y, width: width, height: height)
456 | }
457 |
458 | //MARK: ---开始扫描
459 | func start() {
460 | if Platform.isSimulator {
461 | // Do one thing
462 | print("Please use real machine operation, no this function of simulator")
463 | }
464 | else {
465 | // Do the other
466 | self.captureSession?.startRunning()
467 | }
468 |
469 | }
470 |
471 | //MARK: ---停止
472 | func stop() {
473 | self.captureSession?.stopRunning()
474 | }
475 |
476 | required init?(coder aDecoder: NSCoder) {
477 | fatalError("init(coder:) has not been implemented")
478 | }
479 | //MARK: ---得到扫描结果
480 | func captureOutput(_ captureOutput: AVCaptureOutput!, didOutputMetadataObjects metadataObjects: [Any]!, from connection: AVCaptureConnection!) {
481 | if self.scanType != .barCode {
482 | self.stopLineAnimation()
483 | }
484 | if metadataObjects.count > 0 {
485 | let metadataObject = metadataObjects[0] as! AVMetadataMachineReadableCodeObject
486 | //扫描结果返回试图控制器进行处理
487 | if self.delegate != nil{
488 | self.delegate?.handelTheResult(metadataObject.stringValue)
489 | }
490 |
491 | }
492 | }
493 |
494 | deinit {
495 | NotificationCenter.default.removeObserver(self)
496 | }
497 |
498 | }
499 |
--------------------------------------------------------------------------------
/scanCodeBarCode/QRCodeViewController.swift:
--------------------------------------------------------------------------------
1 | //
2 | // QRCodeViewController.swift
3 | // hunbian
4 | //
5 | // Created by haohao on 16/8/11.
6 | // Copyright © 2016年 haohao. All rights reserved.
7 | //
8 |
9 | import UIKit
10 | import AVFoundation
11 | //播放声音需要的框架
12 | import AudioToolbox
13 |
14 | class QRCodeViewController: UIViewController , UIAlertViewDelegate, HandleTheResultDelegate, UIImagePickerControllerDelegate,UINavigationControllerDelegate{
15 |
16 | var readView : QRCodeReaderView?
17 | var alertView : UIAlertController?
18 |
19 | override func viewDidLoad() {
20 | super.viewDidLoad()
21 |
22 | //添加相册识别二维码的功能
23 |
24 | self.navigationItem.rightBarButtonItem = UIBarButtonItem.init(title: "相册", style: .done, target: self, action: #selector(QRCodeViewController.openLocalPhotoAlbum))
25 |
26 |
27 | // Do any additional setup after loading the view.
28 | self.view.backgroundColor = UIColor.white
29 | self.title = "二维码"
30 | let navBar = UINavigationBar.appearance()
31 | let font = UIFont(name: "Snell Roundhand", size: 20.0)
32 | navBar.titleTextAttributes = [NSForegroundColorAttributeName : UIColor.red, NSFontAttributeName: font!]
33 | self.initScan()
34 | }
35 |
36 | //进入相册
37 | func openLocalPhotoAlbum() {
38 | let picker = UIImagePickerController()
39 |
40 | picker.sourceType = UIImagePickerControllerSourceType.photoLibrary
41 |
42 | picker.delegate = self;
43 |
44 | picker.allowsEditing = true
45 |
46 | present(picker, animated: true, completion: nil)
47 | }
48 | func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : Any]) {
49 | let image:UIImage? = info[UIImagePickerControllerEditedImage] as? UIImage
50 | //识别二维码
51 | if image != nil {
52 | let detector:CIDetector = CIDetector(ofType: CIDetectorTypeQRCode, context: nil, options: [CIDetectorAccuracy:CIDetectorAccuracyHigh])!
53 | let img = CIImage(cgImage: (image?.cgImage)!)
54 | let features : [CIFeature]? = detector.features(in: img, options: [CIDetectorAccuracy:CIDetectorAccuracyHigh])
55 | if features != nil && (features?.count)! > 0 {
56 | let feature = features![0]
57 | if feature.isKind(of: CIQRCodeFeature.self)
58 | {
59 | let featureTmp:CIQRCodeFeature = feature as! CIQRCodeFeature
60 |
61 | let scanResult = featureTmp.messageString
62 | self.handleResult(scanResult!)
63 | }
64 | }
65 |
66 | }
67 | picker.dismiss(animated: true, completion: nil)
68 | }
69 |
70 | //加载扫描框
71 | func initScan() {
72 | let authorStaus = AVCaptureDevice.authorizationStatus(forMediaType: AVMediaTypeVideo)
73 | if [authorStaus == .restricted, authorStaus == .denied].contains(true){
74 | if self.alertView != nil {
75 | self.alertView = nil
76 | }
77 | self.alertView = UIAlertController.init(title: "温馨提示", message: "相机权限受限,请在设置->隐私->相机 中进行设置!", preferredStyle: .alert)
78 | let cancelAction = UIAlertAction.init(title: "取消", style: .cancel, handler: { (cancelaction) in
79 |
80 | })
81 | let setAction = UIAlertAction.init(title: "去设置", style: .default, handler: { (setaction) in
82 | let url = NSURL.init(string: UIApplicationOpenSettingsURLString)
83 | if UIApplication.shared.canOpenURL(url as! URL) {
84 | UIApplication.shared.openURL(url as! URL)
85 | }
86 | })
87 | self.alertView?.addAction(cancelAction)
88 | self.alertView?.addAction(setAction)
89 | self.present(self.alertView!, animated: true, completion: nil)
90 | return
91 | }
92 |
93 | if self.readView != nil{
94 | self.readView?.removeFromSuperview()
95 | self.readView = nil
96 | }
97 | self.readView = QRCodeReaderView.init(frame: UIScreen.main.bounds)
98 | self.readView?.delegate = self
99 | self.readView?.puinMyCodeController = {() in
100 | //进入我的二维码界面
101 | let storyBoard = UIStoryboard.init(name: "Main", bundle: Bundle.main)
102 | let vc = storyBoard.instantiateViewController(withIdentifier: "MineQRCodeViewController")
103 | self.navigationController?.pushViewController(vc, animated: true)
104 | }
105 | self.readView?.backgroundColor = UIColor.white
106 | self.view.addSubview(self.readView!)
107 | }
108 |
109 | //重新扫描的方法
110 | func reStartScan() {
111 | if self.readView?.scanType != .barCode {
112 | self.readView?.creatDrawLine()
113 | self.readView?.startLineAnimation()
114 | }
115 | self.readView?.start()
116 | }
117 |
118 | //View将要出现的时候重新扫描
119 | override func viewWillAppear(_ animated: Bool) {
120 | super.viewWillAppear(animated)
121 | if self.readView != nil {
122 | self.reStartScan()
123 | }
124 | }
125 |
126 | override func viewDidDisappear(_ animated: Bool) {
127 | super.viewDidDisappear(animated)
128 | if self.readView != nil {
129 | self.readView?.stop()
130 | }
131 | }
132 |
133 | //处理扫描结果
134 | func handleResult(_ result: String) {
135 | print("处理扫描结果\(result)")
136 | }
137 |
138 | //MARK: ---UIAlertViewDelegate
139 | func alertView(_ alertView: UIAlertView, clickedButtonAt buttonIndex: Int) {
140 | if buttonIndex == 1 {
141 | print("去设置")
142 | }
143 | }
144 |
145 | //MARK:----HandleTheResultDelegate
146 | func handelTheResult(_ metadataObjectString: String) {
147 | //停止扫描
148 | self.readView?.stop()
149 | //播放扫描二维码的声音
150 | //这个只能播放不超过30秒的声音,它支持的文件格式有限,具体的说只有CAF、AIF和使用PCM或IMA/ADPCM数据的WAV文件
151 | //声音地址
152 | let path = Bundle.main.path(forResource: "noticeMusic", ofType: "wav")
153 | //建立的systemSoundID对象
154 | var soundID : SystemSoundID = 0
155 | let baseURL = URL(fileURLWithPath: path!)
156 | //赋值
157 | AudioServicesCreateSystemSoundID(baseURL as CFURL, &soundID)
158 | //播放声音
159 | AudioServicesPlaySystemSound(soundID)
160 |
161 | //如果是提醒的话
162 |
163 | //处理扫描结果
164 | self.handleResult(metadataObjectString)
165 |
166 | }
167 |
168 | override func didReceiveMemoryWarning() {
169 | super.didReceiveMemoryWarning()
170 | // Dispose of any resources that can be recreated.
171 | }
172 |
173 |
174 | /*
175 | // MARK: - Navigation
176 |
177 | // In a storyboard-based application, you will often want to do a little preparation before navigation
178 | override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
179 | // Get the new view controller using segue.destinationViewController.
180 | // Pass the selected object to the new view controller.
181 | }
182 | */
183 |
184 | }
185 |
--------------------------------------------------------------------------------
/scanCodeBarCode/ViewController.swift:
--------------------------------------------------------------------------------
1 | //
2 | // ViewController.swift
3 | // scanCodeBarCode
4 | //
5 | // Created by haohao on 16/8/16.
6 | // Copyright © 2016年 haohao. All rights reserved.
7 | //
8 |
9 | import UIKit
10 |
11 | class ViewController: UIViewController {
12 |
13 | override func viewDidLoad() {
14 | super.viewDidLoad()
15 | // Do any additional setup after loading the view, typically from a nib.
16 | }
17 |
18 | override func didReceiveMemoryWarning() {
19 | super.didReceiveMemoryWarning()
20 | // Dispose of any resources that can be recreated.
21 | }
22 |
23 |
24 | }
25 |
26 |
--------------------------------------------------------------------------------
/scanCodeBarCode/noticeMusic.wav:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zhanghongdou/QRCodeReaderView-Swift/ef069e0193081ff821440675804bad5a17933e0b/scanCodeBarCode/noticeMusic.wav
--------------------------------------------------------------------------------