├── .DS_Store
├── .gitattributes
├── ScanCodeDemo
├── .DS_Store
├── SnapKit
│ ├── .DS_Store
│ ├── Info.plist
│ ├── SnapKit.h
│ ├── ConstraintView.swift
│ ├── ConstraintInsets.swift
│ ├── ConstraintLayoutSupport.swift
│ ├── UILayoutSupport+Extensions.swift
│ ├── ConstraintLayoutGuide+Extensions.swift
│ ├── ConstraintLayoutGuide.swift
│ ├── ConstraintConfig.swift
│ ├── Typealiases.swift
│ ├── ConstraintRelation.swift
│ ├── ConstraintMakerFinalizable.swift
│ ├── ConstraintRelatableTarget.swift
│ ├── LayoutConstraint.swift
│ ├── ConstraintLayoutSupportDSL.swift
│ ├── ConstraintItem.swift
│ ├── ConstraintMakerEditable.swift
│ ├── ConstraintMultiplierTarget.swift
│ ├── ConstraintOffsetTarget.swift
│ ├── ConstraintPriorityTarget.swift
│ ├── ConstraintLayoutGuideDSL.swift
│ ├── ConstraintPriority.swift
│ ├── ConstraintMakerPriortizable.swift
│ ├── ConstraintDescription.swift
│ ├── ConstraintInsetTarget.swift
│ ├── LayoutConstraintItem.swift
│ ├── ConstraintViewDSL.swift
│ ├── ConstraintMakerRelatable.swift
│ ├── ConstraintMakerExtendable.swift
│ ├── ConstraintConstantTarget.swift
│ ├── Debugging.swift
│ ├── ConstraintDSL.swift
│ ├── ConstraintView+Extensions.swift
│ ├── ConstraintAttributes.swift
│ ├── ConstraintMaker.swift
│ └── Constraint.swift
├── ScanCode
│ ├── .DS_Store
│ ├── view
│ │ ├── YTNoMenuTextField.swift
│ │ └── YTScanCodeView.swift
│ └── controller
│ │ └── YTScanCodeViewController.swift
├── Assets.xcassets
│ ├── Contents.json
│ ├── line.imageset
│ │ ├── line@2x.png
│ │ ├── line@3x.png
│ │ └── Contents.json
│ ├── pick_bg.imageset
│ │ ├── pick_bg.png
│ │ ├── pick_bg@2x.png
│ │ ├── pick_bg@3x.png
│ │ └── Contents.json
│ ├── vin扫描.imageset
│ │ ├── vin扫描@3x.png
│ │ ├── vin扫描@3x@2x.png
│ │ ├── vin扫描@3x@3x.png
│ │ └── Contents.json
│ ├── backspace.imageset
│ │ ├── backspace@2x.png
│ │ ├── backspace@3x.png
│ │ └── Contents.json
│ ├── scan_capture.imageset
│ │ ├── scan_capture.png
│ │ ├── scan_capture@2x.png
│ │ ├── scan_capture@3x.png
│ │ └── Contents.json
│ ├── rewordspace.imageset
│ │ ├── rewordspace@2x.png
│ │ ├── rewordspace@3x.png
│ │ └── Contents.json
│ ├── scan_vin_code.imageset
│ │ ├── scan_vin_code.png
│ │ ├── scan_vin_code@2x.png
│ │ ├── scan_vin_code@3x.png
│ │ └── Contents.json
│ ├── scan_vin_code_pre.imageset
│ │ ├── scan_vin_code_pre.png
│ │ ├── scan_vin_code_pre@2x.png
│ │ ├── scan_vin_code_pre@3x.png
│ │ └── Contents.json
│ ├── Keyboard_Backspace.imageset
│ │ ├── Keyboard_Backspace@2x.png
│ │ ├── Keyboard_Backspace@3x.png
│ │ └── Contents.json
│ ├── scan_dimension_code.imageset
│ │ ├── scan_dimension_code.png
│ │ ├── scan_dimension_code@2x.png
│ │ ├── scan_dimension_code@3x.png
│ │ └── Contents.json
│ ├── scan_dimension_code_pre.imageset
│ │ ├── scan_dimension_code_pre.png
│ │ ├── scan_dimension_code_pre@2x.png
│ │ ├── scan_dimension_code_pre@3x.png
│ │ └── Contents.json
│ └── AppIcon.appiconset
│ │ └── Contents.json
├── base
│ ├── NSObject+Addtionss.swift
│ ├── QGToast.swift
│ └── UIImage+Additions.swift
├── Info.plist
├── Base.lproj
│ ├── Main.storyboard
│ └── LaunchScreen.storyboard
├── AppDelegate.swift
└── ViewController.swift
├── images
├── 51CEE2A1475EC79020E55F5730D529E2.jpg
└── F487BBAB28DFC7602E4D209ED85D42B0.jpg
├── ScanCodeDemo.xcodeproj
└── project.xcworkspace
│ ├── contents.xcworkspacedata
│ └── xcshareddata
│ └── IDEWorkspaceChecks.plist
├── README.md
└── .gitignore
/.DS_Store:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/YTiOSer/ScanCode_Swift/HEAD/.DS_Store
--------------------------------------------------------------------------------
/.gitattributes:
--------------------------------------------------------------------------------
1 | # Auto detect text files and perform LF normalization
2 | * text=auto
3 |
--------------------------------------------------------------------------------
/ScanCodeDemo/.DS_Store:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/YTiOSer/ScanCode_Swift/HEAD/ScanCodeDemo/.DS_Store
--------------------------------------------------------------------------------
/ScanCodeDemo/SnapKit/.DS_Store:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/YTiOSer/ScanCode_Swift/HEAD/ScanCodeDemo/SnapKit/.DS_Store
--------------------------------------------------------------------------------
/ScanCodeDemo/ScanCode/.DS_Store:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/YTiOSer/ScanCode_Swift/HEAD/ScanCodeDemo/ScanCode/.DS_Store
--------------------------------------------------------------------------------
/ScanCodeDemo/Assets.xcassets/Contents.json:
--------------------------------------------------------------------------------
1 | {
2 | "info" : {
3 | "version" : 1,
4 | "author" : "xcode"
5 | }
6 | }
--------------------------------------------------------------------------------
/images/51CEE2A1475EC79020E55F5730D529E2.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/YTiOSer/ScanCode_Swift/HEAD/images/51CEE2A1475EC79020E55F5730D529E2.jpg
--------------------------------------------------------------------------------
/images/F487BBAB28DFC7602E4D209ED85D42B0.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/YTiOSer/ScanCode_Swift/HEAD/images/F487BBAB28DFC7602E4D209ED85D42B0.jpg
--------------------------------------------------------------------------------
/ScanCodeDemo/Assets.xcassets/line.imageset/line@2x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/YTiOSer/ScanCode_Swift/HEAD/ScanCodeDemo/Assets.xcassets/line.imageset/line@2x.png
--------------------------------------------------------------------------------
/ScanCodeDemo/Assets.xcassets/line.imageset/line@3x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/YTiOSer/ScanCode_Swift/HEAD/ScanCodeDemo/Assets.xcassets/line.imageset/line@3x.png
--------------------------------------------------------------------------------
/ScanCodeDemo/Assets.xcassets/pick_bg.imageset/pick_bg.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/YTiOSer/ScanCode_Swift/HEAD/ScanCodeDemo/Assets.xcassets/pick_bg.imageset/pick_bg.png
--------------------------------------------------------------------------------
/ScanCodeDemo/Assets.xcassets/vin扫描.imageset/vin扫描@3x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/YTiOSer/ScanCode_Swift/HEAD/ScanCodeDemo/Assets.xcassets/vin扫描.imageset/vin扫描@3x.png
--------------------------------------------------------------------------------
/ScanCodeDemo/Assets.xcassets/pick_bg.imageset/pick_bg@2x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/YTiOSer/ScanCode_Swift/HEAD/ScanCodeDemo/Assets.xcassets/pick_bg.imageset/pick_bg@2x.png
--------------------------------------------------------------------------------
/ScanCodeDemo/Assets.xcassets/pick_bg.imageset/pick_bg@3x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/YTiOSer/ScanCode_Swift/HEAD/ScanCodeDemo/Assets.xcassets/pick_bg.imageset/pick_bg@3x.png
--------------------------------------------------------------------------------
/ScanCodeDemo/Assets.xcassets/vin扫描.imageset/vin扫描@3x@2x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/YTiOSer/ScanCode_Swift/HEAD/ScanCodeDemo/Assets.xcassets/vin扫描.imageset/vin扫描@3x@2x.png
--------------------------------------------------------------------------------
/ScanCodeDemo/Assets.xcassets/vin扫描.imageset/vin扫描@3x@3x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/YTiOSer/ScanCode_Swift/HEAD/ScanCodeDemo/Assets.xcassets/vin扫描.imageset/vin扫描@3x@3x.png
--------------------------------------------------------------------------------
/ScanCodeDemo/Assets.xcassets/backspace.imageset/backspace@2x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/YTiOSer/ScanCode_Swift/HEAD/ScanCodeDemo/Assets.xcassets/backspace.imageset/backspace@2x.png
--------------------------------------------------------------------------------
/ScanCodeDemo/Assets.xcassets/backspace.imageset/backspace@3x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/YTiOSer/ScanCode_Swift/HEAD/ScanCodeDemo/Assets.xcassets/backspace.imageset/backspace@3x.png
--------------------------------------------------------------------------------
/ScanCodeDemo/Assets.xcassets/scan_capture.imageset/scan_capture.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/YTiOSer/ScanCode_Swift/HEAD/ScanCodeDemo/Assets.xcassets/scan_capture.imageset/scan_capture.png
--------------------------------------------------------------------------------
/ScanCodeDemo/Assets.xcassets/rewordspace.imageset/rewordspace@2x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/YTiOSer/ScanCode_Swift/HEAD/ScanCodeDemo/Assets.xcassets/rewordspace.imageset/rewordspace@2x.png
--------------------------------------------------------------------------------
/ScanCodeDemo/Assets.xcassets/rewordspace.imageset/rewordspace@3x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/YTiOSer/ScanCode_Swift/HEAD/ScanCodeDemo/Assets.xcassets/rewordspace.imageset/rewordspace@3x.png
--------------------------------------------------------------------------------
/ScanCodeDemo/Assets.xcassets/scan_capture.imageset/scan_capture@2x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/YTiOSer/ScanCode_Swift/HEAD/ScanCodeDemo/Assets.xcassets/scan_capture.imageset/scan_capture@2x.png
--------------------------------------------------------------------------------
/ScanCodeDemo/Assets.xcassets/scan_capture.imageset/scan_capture@3x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/YTiOSer/ScanCode_Swift/HEAD/ScanCodeDemo/Assets.xcassets/scan_capture.imageset/scan_capture@3x.png
--------------------------------------------------------------------------------
/ScanCodeDemo/Assets.xcassets/scan_vin_code.imageset/scan_vin_code.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/YTiOSer/ScanCode_Swift/HEAD/ScanCodeDemo/Assets.xcassets/scan_vin_code.imageset/scan_vin_code.png
--------------------------------------------------------------------------------
/ScanCodeDemo/Assets.xcassets/scan_vin_code.imageset/scan_vin_code@2x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/YTiOSer/ScanCode_Swift/HEAD/ScanCodeDemo/Assets.xcassets/scan_vin_code.imageset/scan_vin_code@2x.png
--------------------------------------------------------------------------------
/ScanCodeDemo/Assets.xcassets/scan_vin_code.imageset/scan_vin_code@3x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/YTiOSer/ScanCode_Swift/HEAD/ScanCodeDemo/Assets.xcassets/scan_vin_code.imageset/scan_vin_code@3x.png
--------------------------------------------------------------------------------
/ScanCodeDemo/Assets.xcassets/scan_vin_code_pre.imageset/scan_vin_code_pre.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/YTiOSer/ScanCode_Swift/HEAD/ScanCodeDemo/Assets.xcassets/scan_vin_code_pre.imageset/scan_vin_code_pre.png
--------------------------------------------------------------------------------
/ScanCodeDemo/Assets.xcassets/scan_vin_code_pre.imageset/scan_vin_code_pre@2x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/YTiOSer/ScanCode_Swift/HEAD/ScanCodeDemo/Assets.xcassets/scan_vin_code_pre.imageset/scan_vin_code_pre@2x.png
--------------------------------------------------------------------------------
/ScanCodeDemo/Assets.xcassets/scan_vin_code_pre.imageset/scan_vin_code_pre@3x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/YTiOSer/ScanCode_Swift/HEAD/ScanCodeDemo/Assets.xcassets/scan_vin_code_pre.imageset/scan_vin_code_pre@3x.png
--------------------------------------------------------------------------------
/ScanCodeDemo/Assets.xcassets/Keyboard_Backspace.imageset/Keyboard_Backspace@2x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/YTiOSer/ScanCode_Swift/HEAD/ScanCodeDemo/Assets.xcassets/Keyboard_Backspace.imageset/Keyboard_Backspace@2x.png
--------------------------------------------------------------------------------
/ScanCodeDemo/Assets.xcassets/Keyboard_Backspace.imageset/Keyboard_Backspace@3x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/YTiOSer/ScanCode_Swift/HEAD/ScanCodeDemo/Assets.xcassets/Keyboard_Backspace.imageset/Keyboard_Backspace@3x.png
--------------------------------------------------------------------------------
/ScanCodeDemo/Assets.xcassets/scan_dimension_code.imageset/scan_dimension_code.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/YTiOSer/ScanCode_Swift/HEAD/ScanCodeDemo/Assets.xcassets/scan_dimension_code.imageset/scan_dimension_code.png
--------------------------------------------------------------------------------
/ScanCodeDemo/Assets.xcassets/scan_dimension_code.imageset/scan_dimension_code@2x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/YTiOSer/ScanCode_Swift/HEAD/ScanCodeDemo/Assets.xcassets/scan_dimension_code.imageset/scan_dimension_code@2x.png
--------------------------------------------------------------------------------
/ScanCodeDemo/Assets.xcassets/scan_dimension_code.imageset/scan_dimension_code@3x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/YTiOSer/ScanCode_Swift/HEAD/ScanCodeDemo/Assets.xcassets/scan_dimension_code.imageset/scan_dimension_code@3x.png
--------------------------------------------------------------------------------
/ScanCodeDemo/Assets.xcassets/scan_dimension_code_pre.imageset/scan_dimension_code_pre.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/YTiOSer/ScanCode_Swift/HEAD/ScanCodeDemo/Assets.xcassets/scan_dimension_code_pre.imageset/scan_dimension_code_pre.png
--------------------------------------------------------------------------------
/ScanCodeDemo/Assets.xcassets/scan_dimension_code_pre.imageset/scan_dimension_code_pre@2x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/YTiOSer/ScanCode_Swift/HEAD/ScanCodeDemo/Assets.xcassets/scan_dimension_code_pre.imageset/scan_dimension_code_pre@2x.png
--------------------------------------------------------------------------------
/ScanCodeDemo/Assets.xcassets/scan_dimension_code_pre.imageset/scan_dimension_code_pre@3x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/YTiOSer/ScanCode_Swift/HEAD/ScanCodeDemo/Assets.xcassets/scan_dimension_code_pre.imageset/scan_dimension_code_pre@3x.png
--------------------------------------------------------------------------------
/ScanCodeDemo.xcodeproj/project.xcworkspace/contents.xcworkspacedata:
--------------------------------------------------------------------------------
1 |
2 |
4 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/ScanCodeDemo.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | IDEDidComputeMac32BitWarning
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # ScanCode-Swift
2 |
3 | >基于swift的二维码 VIN码扫描 识别, 同时支持拍照和相册选择识别, 功能强大, 集成代码简单.
4 |
5 | 效果图如下
6 |
7 | 二维码:
8 | 
9 |
10 | VIN码:
11 | 
12 |
--------------------------------------------------------------------------------
/ScanCodeDemo/ScanCode/view/YTNoMenuTextField.swift:
--------------------------------------------------------------------------------
1 | //
2 | // YTNoMenuTextField.swift
3 | // ScanCodeDemo
4 | //
5 | // Created by YTiOSer on 18/5.
6 | // Copyright © 2018 YTiOSer. All rights reserved.
7 | //
8 |
9 | import UIKit
10 |
11 | class YTNoMenuTextField: UITextField {
12 |
13 | override func canPerformAction(_ action: Selector, withSender sender: Any?) -> Bool {
14 | return false
15 | }
16 |
17 | }
18 |
--------------------------------------------------------------------------------
/ScanCodeDemo/Assets.xcassets/line.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 | "filename" : "line@3x.png",
15 | "scale" : "3x"
16 | }
17 | ],
18 | "info" : {
19 | "version" : 1,
20 | "author" : "xcode"
21 | }
22 | }
--------------------------------------------------------------------------------
/ScanCodeDemo/Assets.xcassets/backspace.imageset/Contents.json:
--------------------------------------------------------------------------------
1 | {
2 | "images" : [
3 | {
4 | "idiom" : "universal",
5 | "scale" : "1x"
6 | },
7 | {
8 | "idiom" : "universal",
9 | "filename" : "backspace@2x.png",
10 | "scale" : "2x"
11 | },
12 | {
13 | "idiom" : "universal",
14 | "filename" : "backspace@3x.png",
15 | "scale" : "3x"
16 | }
17 | ],
18 | "info" : {
19 | "version" : 1,
20 | "author" : "xcode"
21 | }
22 | }
--------------------------------------------------------------------------------
/ScanCodeDemo/Assets.xcassets/rewordspace.imageset/Contents.json:
--------------------------------------------------------------------------------
1 | {
2 | "images" : [
3 | {
4 | "idiom" : "universal",
5 | "scale" : "1x"
6 | },
7 | {
8 | "idiom" : "universal",
9 | "filename" : "rewordspace@2x.png",
10 | "scale" : "2x"
11 | },
12 | {
13 | "idiom" : "universal",
14 | "filename" : "rewordspace@3x.png",
15 | "scale" : "3x"
16 | }
17 | ],
18 | "info" : {
19 | "version" : 1,
20 | "author" : "xcode"
21 | }
22 | }
--------------------------------------------------------------------------------
/ScanCodeDemo/Assets.xcassets/Keyboard_Backspace.imageset/Contents.json:
--------------------------------------------------------------------------------
1 | {
2 | "images" : [
3 | {
4 | "idiom" : "universal",
5 | "scale" : "1x"
6 | },
7 | {
8 | "idiom" : "universal",
9 | "filename" : "Keyboard_Backspace@2x.png",
10 | "scale" : "2x"
11 | },
12 | {
13 | "idiom" : "universal",
14 | "filename" : "Keyboard_Backspace@3x.png",
15 | "scale" : "3x"
16 | }
17 | ],
18 | "info" : {
19 | "version" : 1,
20 | "author" : "xcode"
21 | }
22 | }
--------------------------------------------------------------------------------
/ScanCodeDemo/Assets.xcassets/pick_bg.imageset/Contents.json:
--------------------------------------------------------------------------------
1 | {
2 | "images" : [
3 | {
4 | "idiom" : "universal",
5 | "filename" : "pick_bg.png",
6 | "scale" : "1x"
7 | },
8 | {
9 | "idiom" : "universal",
10 | "filename" : "pick_bg@2x.png",
11 | "scale" : "2x"
12 | },
13 | {
14 | "idiom" : "universal",
15 | "filename" : "pick_bg@3x.png",
16 | "scale" : "3x"
17 | }
18 | ],
19 | "info" : {
20 | "version" : 1,
21 | "author" : "xcode"
22 | }
23 | }
--------------------------------------------------------------------------------
/ScanCodeDemo/Assets.xcassets/vin扫描.imageset/Contents.json:
--------------------------------------------------------------------------------
1 | {
2 | "images" : [
3 | {
4 | "idiom" : "universal",
5 | "filename" : "vin扫描@3x.png",
6 | "scale" : "1x"
7 | },
8 | {
9 | "idiom" : "universal",
10 | "filename" : "vin扫描@3x@2x.png",
11 | "scale" : "2x"
12 | },
13 | {
14 | "idiom" : "universal",
15 | "filename" : "vin扫描@3x@3x.png",
16 | "scale" : "3x"
17 | }
18 | ],
19 | "info" : {
20 | "version" : 1,
21 | "author" : "xcode"
22 | }
23 | }
--------------------------------------------------------------------------------
/ScanCodeDemo/Assets.xcassets/scan_capture.imageset/Contents.json:
--------------------------------------------------------------------------------
1 | {
2 | "images" : [
3 | {
4 | "idiom" : "universal",
5 | "filename" : "scan_capture.png",
6 | "scale" : "1x"
7 | },
8 | {
9 | "idiom" : "universal",
10 | "filename" : "scan_capture@2x.png",
11 | "scale" : "2x"
12 | },
13 | {
14 | "idiom" : "universal",
15 | "filename" : "scan_capture@3x.png",
16 | "scale" : "3x"
17 | }
18 | ],
19 | "info" : {
20 | "version" : 1,
21 | "author" : "xcode"
22 | }
23 | }
--------------------------------------------------------------------------------
/ScanCodeDemo/Assets.xcassets/scan_vin_code.imageset/Contents.json:
--------------------------------------------------------------------------------
1 | {
2 | "images" : [
3 | {
4 | "idiom" : "universal",
5 | "filename" : "scan_vin_code.png",
6 | "scale" : "1x"
7 | },
8 | {
9 | "idiom" : "universal",
10 | "filename" : "scan_vin_code@2x.png",
11 | "scale" : "2x"
12 | },
13 | {
14 | "idiom" : "universal",
15 | "filename" : "scan_vin_code@3x.png",
16 | "scale" : "3x"
17 | }
18 | ],
19 | "info" : {
20 | "version" : 1,
21 | "author" : "xcode"
22 | }
23 | }
--------------------------------------------------------------------------------
/ScanCodeDemo/Assets.xcassets/scan_vin_code_pre.imageset/Contents.json:
--------------------------------------------------------------------------------
1 | {
2 | "images" : [
3 | {
4 | "idiom" : "universal",
5 | "filename" : "scan_vin_code_pre.png",
6 | "scale" : "1x"
7 | },
8 | {
9 | "idiom" : "universal",
10 | "filename" : "scan_vin_code_pre@2x.png",
11 | "scale" : "2x"
12 | },
13 | {
14 | "idiom" : "universal",
15 | "filename" : "scan_vin_code_pre@3x.png",
16 | "scale" : "3x"
17 | }
18 | ],
19 | "info" : {
20 | "version" : 1,
21 | "author" : "xcode"
22 | }
23 | }
--------------------------------------------------------------------------------
/ScanCodeDemo/Assets.xcassets/scan_dimension_code.imageset/Contents.json:
--------------------------------------------------------------------------------
1 | {
2 | "images" : [
3 | {
4 | "idiom" : "universal",
5 | "filename" : "scan_dimension_code.png",
6 | "scale" : "1x"
7 | },
8 | {
9 | "idiom" : "universal",
10 | "filename" : "scan_dimension_code@2x.png",
11 | "scale" : "2x"
12 | },
13 | {
14 | "idiom" : "universal",
15 | "filename" : "scan_dimension_code@3x.png",
16 | "scale" : "3x"
17 | }
18 | ],
19 | "info" : {
20 | "version" : 1,
21 | "author" : "xcode"
22 | }
23 | }
--------------------------------------------------------------------------------
/ScanCodeDemo/Assets.xcassets/scan_dimension_code_pre.imageset/Contents.json:
--------------------------------------------------------------------------------
1 | {
2 | "images" : [
3 | {
4 | "idiom" : "universal",
5 | "filename" : "scan_dimension_code_pre.png",
6 | "scale" : "1x"
7 | },
8 | {
9 | "idiom" : "universal",
10 | "filename" : "scan_dimension_code_pre@2x.png",
11 | "scale" : "2x"
12 | },
13 | {
14 | "idiom" : "universal",
15 | "filename" : "scan_dimension_code_pre@3x.png",
16 | "scale" : "3x"
17 | }
18 | ],
19 | "info" : {
20 | "version" : 1,
21 | "author" : "xcode"
22 | }
23 | }
--------------------------------------------------------------------------------
/ScanCodeDemo/SnapKit/Info.plist:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | CFBundleDevelopmentRegion
6 | en
7 | CFBundleExecutable
8 | $(EXECUTABLE_NAME)
9 | CFBundleIdentifier
10 | $(PRODUCT_BUNDLE_IDENTIFIER)
11 | CFBundleInfoDictionaryVersion
12 | 6.0
13 | CFBundleName
14 | $(PRODUCT_NAME)
15 | CFBundlePackageType
16 | $(PRODUCT_BUNDLE_PACKAGE_TYPE)
17 | CFBundleShortVersionString
18 | $(CURRENT_PROJECT_VERSION)
19 | CFBundleSignature
20 | ????
21 | CFBundleVersion
22 | $(CURRENT_PROJECT_VERSION)
23 | NSPrincipalClass
24 |
25 |
26 |
27 |
--------------------------------------------------------------------------------
/ScanCodeDemo/SnapKit/SnapKit.h:
--------------------------------------------------------------------------------
1 | //
2 | // SnapKit
3 | //
4 | // Copyright (c) 2011-Present SnapKit Team - https://github.com/SnapKit
5 | //
6 | // Permission is hereby granted, free of charge, to any person obtaining a copy
7 | // of this software and associated documentation files (the "Software"), to deal
8 | // in the Software without restriction, including without limitation the rights
9 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 | // copies of the Software, and to permit persons to whom the Software is
11 | // furnished to do so, subject to the following conditions:
12 | //
13 | // The above copyright notice and this permission notice shall be included in
14 | // all copies or substantial portions of the Software.
15 | //
16 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22 | // THE SOFTWARE.
23 |
24 | #import
25 |
26 | FOUNDATION_EXPORT double SnapKitVersionNumber;
27 | FOUNDATION_EXPORT const unsigned char SnapKitVersionString[];
--------------------------------------------------------------------------------
/ScanCodeDemo/SnapKit/ConstraintView.swift:
--------------------------------------------------------------------------------
1 | //
2 | // SnapKit
3 | //
4 | // Copyright (c) 2011-Present SnapKit Team - https://github.com/SnapKit
5 | //
6 | // Permission is hereby granted, free of charge, to any person obtaining a copy
7 | // of this software and associated documentation files (the "Software"), to deal
8 | // in the Software without restriction, including without limitation the rights
9 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 | // copies of the Software, and to permit persons to whom the Software is
11 | // furnished to do so, subject to the following conditions:
12 | //
13 | // The above copyright notice and this permission notice shall be included in
14 | // all copies or substantial portions of the Software.
15 | //
16 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22 | // THE SOFTWARE.
23 |
24 | #if os(iOS) || os(tvOS)
25 | import UIKit
26 | #else
27 | import AppKit
28 | #endif
29 |
30 |
31 | #if os(iOS) || os(tvOS)
32 | public typealias ConstraintView = UIView
33 | #else
34 | public typealias ConstraintView = NSView
35 | #endif
36 |
--------------------------------------------------------------------------------
/ScanCodeDemo/SnapKit/ConstraintInsets.swift:
--------------------------------------------------------------------------------
1 | //
2 | // SnapKit
3 | //
4 | // Copyright (c) 2011-Present SnapKit Team - https://github.com/SnapKit
5 | //
6 | // Permission is hereby granted, free of charge, to any person obtaining a copy
7 | // of this software and associated documentation files (the "Software"), to deal
8 | // in the Software without restriction, including without limitation the rights
9 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 | // copies of the Software, and to permit persons to whom the Software is
11 | // furnished to do so, subject to the following conditions:
12 | //
13 | // The above copyright notice and this permission notice shall be included in
14 | // all copies or substantial portions of the Software.
15 | //
16 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22 | // THE SOFTWARE.
23 |
24 | #if os(iOS) || os(tvOS)
25 | import UIKit
26 | #else
27 | import AppKit
28 | #endif
29 |
30 |
31 | #if os(iOS) || os(tvOS)
32 | public typealias ConstraintInsets = UIEdgeInsets
33 | #else
34 | public typealias ConstraintInsets = NSEdgeInsets
35 | #endif
36 |
--------------------------------------------------------------------------------
/ScanCodeDemo/base/NSObject+Addtionss.swift:
--------------------------------------------------------------------------------
1 | //
2 | // NSObject+Addtionss.swift
3 | // B2BAutoziMall
4 | //
5 | // Created by YTiOSer on 18/5.
6 | // Copyright © 2018 YTiOSer. All rights reserved.
7 | //
8 |
9 | import UIKit
10 |
11 | extension NSObject {
12 |
13 | /// 设置关联对象
14 | func setAssociatedObject(_ obj:AnyObject,key:UnsafeRawPointer) {
15 | objc_setAssociatedObject(self, key, obj, .OBJC_ASSOCIATION_RETAIN_NONATOMIC)
16 | }
17 |
18 | /// 获取关联对象
19 | func associatedObjectForKey(_ key:UnsafeRawPointer) -> AnyObject? {
20 | return objc_getAssociatedObject(self, key) as AnyObject?
21 | }
22 |
23 | /// 去掉所有关联对象
24 | func removeAssociatedObjects() {
25 | objc_removeAssociatedObjects(self)
26 | }
27 |
28 | func showToast(_ text: String,duration:TimeInterval = 2.0) {
29 | if text.isEmpty { return }
30 | let _ = QGToast(text: text,duration:duration)
31 | }
32 |
33 | func postNotification(_ name:String,object:AnyObject? = nil,userInfo:[String:AnyObject]? = nil) {
34 | NotificationCenter.default.post(name: Notification.Name(rawValue: name), object: object,userInfo:userInfo )
35 | }
36 |
37 | func addNotificationObserver(_ selector:Selector,name:String?,object:AnyObject?) {
38 | NotificationCenter.default.addObserver(self, selector: selector, name: name.map { NSNotification.Name(rawValue: $0) }, object: object)
39 | }
40 |
41 | func removeNotificationObserver() {
42 | NotificationCenter.default.removeObserver(self)
43 | }
44 | }
45 |
46 |
47 |
--------------------------------------------------------------------------------
/ScanCodeDemo/SnapKit/ConstraintLayoutSupport.swift:
--------------------------------------------------------------------------------
1 | //
2 | // SnapKit
3 | //
4 | // Copyright (c) 2011-Present SnapKit Team - https://github.com/SnapKit
5 | //
6 | // Permission is hereby granted, free of charge, to any person obtaining a copy
7 | // of this software and associated documentation files (the "Software"), to deal
8 | // in the Software without restriction, including without limitation the rights
9 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 | // copies of the Software, and to permit persons to whom the Software is
11 | // furnished to do so, subject to the following conditions:
12 | //
13 | // The above copyright notice and this permission notice shall be included in
14 | // all copies or substantial portions of the Software.
15 | //
16 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22 | // THE SOFTWARE.
23 |
24 | #if os(iOS) || os(tvOS)
25 | import UIKit
26 | #else
27 | import AppKit
28 | #endif
29 |
30 |
31 | #if os(iOS) || os(tvOS)
32 | @available(iOS 8.0, *)
33 | public typealias ConstraintLayoutSupport = UILayoutSupport
34 | #else
35 | public class ConstraintLayoutSupport {}
36 | #endif
37 |
--------------------------------------------------------------------------------
/ScanCodeDemo/SnapKit/UILayoutSupport+Extensions.swift:
--------------------------------------------------------------------------------
1 | //
2 | // SnapKit
3 | //
4 | // Copyright (c) 2011-Present SnapKit Team - https://github.com/SnapKit
5 | //
6 | // Permission is hereby granted, free of charge, to any person obtaining a copy
7 | // of this software and associated documentation files (the "Software"), to deal
8 | // in the Software without restriction, including without limitation the rights
9 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 | // copies of the Software, and to permit persons to whom the Software is
11 | // furnished to do so, subject to the following conditions:
12 | //
13 | // The above copyright notice and this permission notice shall be included in
14 | // all copies or substantial portions of the Software.
15 | //
16 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22 | // THE SOFTWARE.
23 |
24 | #if os(iOS) || os(tvOS)
25 | import UIKit
26 | #endif
27 |
28 |
29 | @available(iOS 8.0, *)
30 | public extension ConstraintLayoutSupport {
31 |
32 | public var snp: ConstraintLayoutSupportDSL {
33 | return ConstraintLayoutSupportDSL(support: self)
34 | }
35 |
36 | }
37 |
--------------------------------------------------------------------------------
/ScanCodeDemo/SnapKit/ConstraintLayoutGuide+Extensions.swift:
--------------------------------------------------------------------------------
1 | //
2 | // SnapKit
3 | //
4 | // Copyright (c) 2011-Present SnapKit Team - https://github.com/SnapKit
5 | //
6 | // Permission is hereby granted, free of charge, to any person obtaining a copy
7 | // of this software and associated documentation files (the "Software"), to deal
8 | // in the Software without restriction, including without limitation the rights
9 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 | // copies of the Software, and to permit persons to whom the Software is
11 | // furnished to do so, subject to the following conditions:
12 | //
13 | // The above copyright notice and this permission notice shall be included in
14 | // all copies or substantial portions of the Software.
15 | //
16 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22 | // THE SOFTWARE.
23 |
24 | #if os(iOS) || os(tvOS)
25 | import UIKit
26 | #endif
27 |
28 |
29 | @available(iOS 9.0, OSX 10.11, *)
30 | public extension ConstraintLayoutGuide {
31 |
32 | public var snp: ConstraintLayoutGuideDSL {
33 | return ConstraintLayoutGuideDSL(guide: self)
34 | }
35 |
36 | }
37 |
--------------------------------------------------------------------------------
/ScanCodeDemo/SnapKit/ConstraintLayoutGuide.swift:
--------------------------------------------------------------------------------
1 | //
2 | // SnapKit
3 | //
4 | // Copyright (c) 2011-Present SnapKit Team - https://github.com/SnapKit
5 | //
6 | // Permission is hereby granted, free of charge, to any person obtaining a copy
7 | // of this software and associated documentation files (the "Software"), to deal
8 | // in the Software without restriction, including without limitation the rights
9 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 | // copies of the Software, and to permit persons to whom the Software is
11 | // furnished to do so, subject to the following conditions:
12 | //
13 | // The above copyright notice and this permission notice shall be included in
14 | // all copies or substantial portions of the Software.
15 | //
16 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22 | // THE SOFTWARE.
23 |
24 | #if os(iOS) || os(tvOS)
25 | import UIKit
26 | #else
27 | import AppKit
28 | #endif
29 |
30 |
31 | #if os(iOS) || os(tvOS)
32 | @available(iOS 9.0, *)
33 | public typealias ConstraintLayoutGuide = UILayoutGuide
34 | #else
35 | @available(OSX 10.11, *)
36 | public typealias ConstraintLayoutGuide = NSLayoutGuide
37 | #endif
38 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | # Xcode
2 | #
3 | # gitignore contributors: remember to update Global/Xcode.gitignore, Objective-C.gitignore & Swift.gitignore
4 |
5 | ## Build generated
6 | build/
7 | DerivedData/
8 |
9 | ## Various settings
10 | *.pbxuser
11 | !default.pbxuser
12 | *.mode1v3
13 | !default.mode1v3
14 | *.mode2v3
15 | !default.mode2v3
16 | *.perspectivev3
17 | !default.perspectivev3
18 | xcuserdata/
19 |
20 | ## Other
21 | *.moved-aside
22 | *.xccheckout
23 | *.xcscmblueprint
24 |
25 | ## Obj-C/Swift specific
26 | *.hmap
27 | *.ipa
28 | *.dSYM.zip
29 | *.dSYM
30 |
31 | ## Playgrounds
32 | timeline.xctimeline
33 | playground.xcworkspace
34 |
35 | # Swift Package Manager
36 | #
37 | # Add this line if you want to avoid checking in source code from Swift Package Manager dependencies.
38 | # Packages/
39 | # Package.pins
40 | .build/
41 |
42 | # CocoaPods
43 | #
44 | # We recommend against adding the Pods directory to your .gitignore. However
45 | # you should judge for yourself, the pros and cons are mentioned at:
46 | # https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control
47 | #
48 | # Pods/
49 |
50 | # Carthage
51 | #
52 | # Add this line if you want to avoid checking in source code from Carthage dependencies.
53 | # Carthage/Checkouts
54 |
55 | Carthage/Build
56 |
57 | # fastlane
58 | #
59 | # It is recommended to not store the screenshots in the git repo. Instead, use fastlane to re-generate the
60 | # screenshots whenever they are needed.
61 | # For more information about the recommended setup visit:
62 | # https://docs.fastlane.tools/best-practices/source-control/#source-control
63 |
64 | fastlane/report.xml
65 | fastlane/Preview.html
66 | fastlane/screenshots
67 | fastlane/test_output
68 |
--------------------------------------------------------------------------------
/ScanCodeDemo/SnapKit/ConstraintConfig.swift:
--------------------------------------------------------------------------------
1 | //
2 | // SnapKit
3 | //
4 | // Copyright (c) 2011-Present SnapKit Team - https://github.com/SnapKit
5 | //
6 | // Permission is hereby granted, free of charge, to any person obtaining a copy
7 | // of this software and associated documentation files (the "Software"), to deal
8 | // in the Software without restriction, including without limitation the rights
9 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 | // copies of the Software, and to permit persons to whom the Software is
11 | // furnished to do so, subject to the following conditions:
12 | //
13 | // The above copyright notice and this permission notice shall be included in
14 | // all copies or substantial portions of the Software.
15 | //
16 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22 | // THE SOFTWARE.
23 |
24 | #if os(iOS) || os(tvOS)
25 | import UIKit
26 | public typealias ConstraintInterfaceLayoutDirection = UIUserInterfaceLayoutDirection
27 | #else
28 | import AppKit
29 | public typealias ConstraintInterfaceLayoutDirection = NSUserInterfaceLayoutDirection
30 | #endif
31 |
32 |
33 | public struct ConstraintConfig {
34 |
35 | public static var interfaceLayoutDirection: ConstraintInterfaceLayoutDirection = .leftToRight
36 |
37 | }
38 |
--------------------------------------------------------------------------------
/ScanCodeDemo/SnapKit/Typealiases.swift:
--------------------------------------------------------------------------------
1 | //
2 | // SnapKit
3 | //
4 | // Copyright (c) 2011-Present SnapKit Team - https://github.com/SnapKit
5 | //
6 | // Permission is hereby granted, free of charge, to any person obtaining a copy
7 | // of this software and associated documentation files (the "Software"), to deal
8 | // in the Software without restriction, including without limitation the rights
9 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 | // copies of the Software, and to permit persons to whom the Software is
11 | // furnished to do so, subject to the following conditions:
12 | //
13 | // The above copyright notice and this permission notice shall be included in
14 | // all copies or substantial portions of the Software.
15 | //
16 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22 | // THE SOFTWARE.
23 |
24 | import Foundation
25 |
26 | #if os(iOS) || os(tvOS)
27 | import UIKit
28 | typealias LayoutRelation = NSLayoutRelation
29 | typealias LayoutAttribute = NSLayoutAttribute
30 | typealias LayoutPriority = UILayoutPriority
31 | #else
32 | import AppKit
33 | typealias LayoutRelation = NSLayoutConstraint.Relation
34 | typealias LayoutAttribute = NSLayoutConstraint.Attribute
35 | typealias LayoutPriority = NSLayoutConstraint.Priority
36 | #endif
37 |
38 |
--------------------------------------------------------------------------------
/ScanCodeDemo/Info.plist:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | CFBundleDevelopmentRegion
6 | $(DEVELOPMENT_LANGUAGE)
7 | CFBundleExecutable
8 | $(EXECUTABLE_NAME)
9 | CFBundleIdentifier
10 | $(PRODUCT_BUNDLE_IDENTIFIER)
11 | CFBundleInfoDictionaryVersion
12 | 6.0
13 | CFBundleName
14 | $(PRODUCT_NAME)
15 | CFBundlePackageType
16 | APPL
17 | CFBundleShortVersionString
18 | 1.0
19 | CFBundleVersion
20 | 1
21 | LSRequiresIPhoneOS
22 |
23 | NSCameraUsageDescription
24 | 应用需要访问您的相机,以便您正常使用扫码服务
25 | NSPhotoLibraryAddUsageDescription
26 | 应用需要为您添加图片,以便您正常使用扫码服务
27 | NSPhotoLibraryUsageDescription
28 | 应用需要访问您的相册,以便您正常使用扫码服务
29 | UILaunchStoryboardName
30 | LaunchScreen
31 | UIMainStoryboardFile
32 | Main
33 | UIRequiredDeviceCapabilities
34 |
35 | armv7
36 |
37 | UISupportedInterfaceOrientations
38 |
39 | UIInterfaceOrientationPortrait
40 |
41 | UISupportedInterfaceOrientations~ipad
42 |
43 | UIInterfaceOrientationPortrait
44 | UIInterfaceOrientationPortraitUpsideDown
45 | UIInterfaceOrientationLandscapeLeft
46 | UIInterfaceOrientationLandscapeRight
47 |
48 |
49 |
50 |
--------------------------------------------------------------------------------
/ScanCodeDemo/SnapKit/ConstraintRelation.swift:
--------------------------------------------------------------------------------
1 | //
2 | // SnapKit
3 | //
4 | // Copyright (c) 2011-Present SnapKit Team - https://github.com/SnapKit
5 | //
6 | // Permission is hereby granted, free of charge, to any person obtaining a copy
7 | // of this software and associated documentation files (the "Software"), to deal
8 | // in the Software without restriction, including without limitation the rights
9 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 | // copies of the Software, and to permit persons to whom the Software is
11 | // furnished to do so, subject to the following conditions:
12 | //
13 | // The above copyright notice and this permission notice shall be included in
14 | // all copies or substantial portions of the Software.
15 | //
16 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22 | // THE SOFTWARE.
23 |
24 | #if os(iOS) || os(tvOS)
25 | import UIKit
26 | #else
27 | import AppKit
28 | #endif
29 |
30 |
31 | internal enum ConstraintRelation : Int {
32 | case equal = 1
33 | case lessThanOrEqual
34 | case greaterThanOrEqual
35 |
36 | internal var layoutRelation: LayoutRelation {
37 | get {
38 | switch(self) {
39 | case .equal:
40 | return .equal
41 | case .lessThanOrEqual:
42 | return .lessThanOrEqual
43 | case .greaterThanOrEqual:
44 | return .greaterThanOrEqual
45 | }
46 | }
47 | }
48 | }
49 |
--------------------------------------------------------------------------------
/ScanCodeDemo/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 |
--------------------------------------------------------------------------------
/ScanCodeDemo/SnapKit/ConstraintMakerFinalizable.swift:
--------------------------------------------------------------------------------
1 | //
2 | // SnapKit
3 | //
4 | // Copyright (c) 2011-Present SnapKit Team - https://github.com/SnapKit
5 | //
6 | // Permission is hereby granted, free of charge, to any person obtaining a copy
7 | // of this software and associated documentation files (the "Software"), to deal
8 | // in the Software without restriction, including without limitation the rights
9 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 | // copies of the Software, and to permit persons to whom the Software is
11 | // furnished to do so, subject to the following conditions:
12 | //
13 | // The above copyright notice and this permission notice shall be included in
14 | // all copies or substantial portions of the Software.
15 | //
16 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22 | // THE SOFTWARE.
23 |
24 | #if os(iOS) || os(tvOS)
25 | import UIKit
26 | #else
27 | import AppKit
28 | #endif
29 |
30 |
31 | public class ConstraintMakerFinalizable {
32 |
33 | internal let description: ConstraintDescription
34 |
35 | internal init(_ description: ConstraintDescription) {
36 | self.description = description
37 | }
38 |
39 | @discardableResult
40 | public func labeled(_ label: String) -> ConstraintMakerFinalizable {
41 | self.description.label = label
42 | return self
43 | }
44 |
45 | public var constraint: Constraint {
46 | return self.description.constraint!
47 | }
48 |
49 | }
50 |
--------------------------------------------------------------------------------
/ScanCodeDemo/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 |
29 |
30 |
31 |
32 |
--------------------------------------------------------------------------------
/ScanCodeDemo/Assets.xcassets/AppIcon.appiconset/Contents.json:
--------------------------------------------------------------------------------
1 | {
2 | "images" : [
3 | {
4 | "idiom" : "iphone",
5 | "size" : "20x20",
6 | "scale" : "2x"
7 | },
8 | {
9 | "idiom" : "iphone",
10 | "size" : "20x20",
11 | "scale" : "3x"
12 | },
13 | {
14 | "idiom" : "iphone",
15 | "size" : "29x29",
16 | "scale" : "2x"
17 | },
18 | {
19 | "idiom" : "iphone",
20 | "size" : "29x29",
21 | "scale" : "3x"
22 | },
23 | {
24 | "idiom" : "iphone",
25 | "size" : "40x40",
26 | "scale" : "2x"
27 | },
28 | {
29 | "idiom" : "iphone",
30 | "size" : "40x40",
31 | "scale" : "3x"
32 | },
33 | {
34 | "idiom" : "iphone",
35 | "size" : "60x60",
36 | "scale" : "2x"
37 | },
38 | {
39 | "idiom" : "iphone",
40 | "size" : "60x60",
41 | "scale" : "3x"
42 | },
43 | {
44 | "idiom" : "ipad",
45 | "size" : "20x20",
46 | "scale" : "1x"
47 | },
48 | {
49 | "idiom" : "ipad",
50 | "size" : "20x20",
51 | "scale" : "2x"
52 | },
53 | {
54 | "idiom" : "ipad",
55 | "size" : "29x29",
56 | "scale" : "1x"
57 | },
58 | {
59 | "idiom" : "ipad",
60 | "size" : "29x29",
61 | "scale" : "2x"
62 | },
63 | {
64 | "idiom" : "ipad",
65 | "size" : "40x40",
66 | "scale" : "1x"
67 | },
68 | {
69 | "idiom" : "ipad",
70 | "size" : "40x40",
71 | "scale" : "2x"
72 | },
73 | {
74 | "idiom" : "ipad",
75 | "size" : "76x76",
76 | "scale" : "1x"
77 | },
78 | {
79 | "idiom" : "ipad",
80 | "size" : "76x76",
81 | "scale" : "2x"
82 | },
83 | {
84 | "idiom" : "ipad",
85 | "size" : "83.5x83.5",
86 | "scale" : "2x"
87 | },
88 | {
89 | "idiom" : "ios-marketing",
90 | "size" : "1024x1024",
91 | "scale" : "1x"
92 | }
93 | ],
94 | "info" : {
95 | "version" : 1,
96 | "author" : "xcode"
97 | }
98 | }
--------------------------------------------------------------------------------
/ScanCodeDemo/SnapKit/ConstraintRelatableTarget.swift:
--------------------------------------------------------------------------------
1 | //
2 | // SnapKit
3 | //
4 | // Copyright (c) 2011-Present SnapKit Team - https://github.com/SnapKit
5 | //
6 | // Permission is hereby granted, free of charge, to any person obtaining a copy
7 | // of this software and associated documentation files (the "Software"), to deal
8 | // in the Software without restriction, including without limitation the rights
9 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 | // copies of the Software, and to permit persons to whom the Software is
11 | // furnished to do so, subject to the following conditions:
12 | //
13 | // The above copyright notice and this permission notice shall be included in
14 | // all copies or substantial portions of the Software.
15 | //
16 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22 | // THE SOFTWARE.
23 |
24 | #if os(iOS) || os(tvOS)
25 | import UIKit
26 | #else
27 | import AppKit
28 | #endif
29 |
30 |
31 | public protocol ConstraintRelatableTarget {
32 | }
33 |
34 | extension Int: ConstraintRelatableTarget {
35 | }
36 |
37 | extension UInt: ConstraintRelatableTarget {
38 | }
39 |
40 | extension Float: ConstraintRelatableTarget {
41 | }
42 |
43 | extension Double: ConstraintRelatableTarget {
44 | }
45 |
46 | extension CGFloat: ConstraintRelatableTarget {
47 | }
48 |
49 | extension CGSize: ConstraintRelatableTarget {
50 | }
51 |
52 | extension CGPoint: ConstraintRelatableTarget {
53 | }
54 |
55 | extension ConstraintInsets: ConstraintRelatableTarget {
56 | }
57 |
58 | extension ConstraintItem: ConstraintRelatableTarget {
59 | }
60 |
61 | extension ConstraintView: ConstraintRelatableTarget {
62 | }
63 |
64 | @available(iOS 9.0, OSX 10.11, *)
65 | extension ConstraintLayoutGuide: ConstraintRelatableTarget {
66 | }
67 |
--------------------------------------------------------------------------------
/ScanCodeDemo/SnapKit/LayoutConstraint.swift:
--------------------------------------------------------------------------------
1 | //
2 | // SnapKit
3 | //
4 | // Copyright (c) 2011-Present SnapKit Team - https://github.com/SnapKit
5 | //
6 | // Permission is hereby granted, free of charge, to any person obtaining a copy
7 | // of this software and associated documentation files (the "Software"), to deal
8 | // in the Software without restriction, including without limitation the rights
9 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 | // copies of the Software, and to permit persons to whom the Software is
11 | // furnished to do so, subject to the following conditions:
12 | //
13 | // The above copyright notice and this permission notice shall be included in
14 | // all copies or substantial portions of the Software.
15 | //
16 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22 | // THE SOFTWARE.
23 |
24 | #if os(iOS) || os(tvOS)
25 | import UIKit
26 | #else
27 | import AppKit
28 | #endif
29 |
30 |
31 | public class LayoutConstraint : NSLayoutConstraint {
32 |
33 | public var label: String? {
34 | get {
35 | return self.identifier
36 | }
37 | set {
38 | self.identifier = newValue
39 | }
40 | }
41 |
42 | internal weak var constraint: Constraint? = nil
43 |
44 | }
45 |
46 | internal func ==(lhs: LayoutConstraint, rhs: LayoutConstraint) -> Bool {
47 | guard lhs.firstItem === rhs.firstItem &&
48 | lhs.secondItem === rhs.secondItem &&
49 | lhs.firstAttribute == rhs.firstAttribute &&
50 | lhs.secondAttribute == rhs.secondAttribute &&
51 | lhs.relation == rhs.relation &&
52 | lhs.priority == rhs.priority &&
53 | lhs.multiplier == rhs.multiplier else {
54 | return false
55 | }
56 | return true
57 | }
58 |
--------------------------------------------------------------------------------
/ScanCodeDemo/SnapKit/ConstraintLayoutSupportDSL.swift:
--------------------------------------------------------------------------------
1 | //
2 | // SnapKit
3 | //
4 | // Copyright (c) 2011-Present SnapKit Team - https://github.com/SnapKit
5 | //
6 | // Permission is hereby granted, free of charge, to any person obtaining a copy
7 | // of this software and associated documentation files (the "Software"), to deal
8 | // in the Software without restriction, including without limitation the rights
9 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 | // copies of the Software, and to permit persons to whom the Software is
11 | // furnished to do so, subject to the following conditions:
12 | //
13 | // The above copyright notice and this permission notice shall be included in
14 | // all copies or substantial portions of the Software.
15 | //
16 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22 | // THE SOFTWARE.
23 |
24 | #if os(iOS) || os(tvOS)
25 | import UIKit
26 | #else
27 | import AppKit
28 | #endif
29 |
30 |
31 | @available(iOS 8.0, *)
32 | public struct ConstraintLayoutSupportDSL: ConstraintDSL {
33 |
34 | public var target: AnyObject? {
35 | return self.support
36 | }
37 |
38 | internal let support: ConstraintLayoutSupport
39 |
40 | internal init(support: ConstraintLayoutSupport) {
41 | self.support = support
42 |
43 | }
44 |
45 | public var top: ConstraintItem {
46 | return ConstraintItem(target: self.target, attributes: ConstraintAttributes.top)
47 | }
48 |
49 | public var bottom: ConstraintItem {
50 | return ConstraintItem(target: self.target, attributes: ConstraintAttributes.bottom)
51 | }
52 |
53 | public var height: ConstraintItem {
54 | return ConstraintItem(target: self.target, attributes: ConstraintAttributes.height)
55 | }
56 | }
57 |
--------------------------------------------------------------------------------
/ScanCodeDemo/AppDelegate.swift:
--------------------------------------------------------------------------------
1 | //
2 | // AppDelegate.swift
3 | // ScanCodeDemo
4 | //
5 | // Created by YTiOSer on 18/5.
6 | // Copyright © 2018 YTiOSer. 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 invalidate graphics rendering callbacks. 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 active state; here you can undo many of the changes made on entering the background.
34 | }
35 |
36 | func applicationDidBecomeActive(_ application: UIApplication) {
37 | // 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.
38 | }
39 |
40 | func applicationWillTerminate(_ application: UIApplication) {
41 | // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
42 | }
43 |
44 |
45 | }
46 |
47 |
--------------------------------------------------------------------------------
/ScanCodeDemo/SnapKit/ConstraintItem.swift:
--------------------------------------------------------------------------------
1 | //
2 | // SnapKit
3 | //
4 | // Copyright (c) 2011-Present SnapKit Team - https://github.com/SnapKit
5 | //
6 | // Permission is hereby granted, free of charge, to any person obtaining a copy
7 | // of this software and associated documentation files (the "Software"), to deal
8 | // in the Software without restriction, including without limitation the rights
9 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 | // copies of the Software, and to permit persons to whom the Software is
11 | // furnished to do so, subject to the following conditions:
12 | //
13 | // The above copyright notice and this permission notice shall be included in
14 | // all copies or substantial portions of the Software.
15 | //
16 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22 | // THE SOFTWARE.
23 |
24 | #if os(iOS) || os(tvOS)
25 | import UIKit
26 | #else
27 | import AppKit
28 | #endif
29 |
30 |
31 | public final class ConstraintItem {
32 |
33 | internal weak var target: AnyObject?
34 | internal let attributes: ConstraintAttributes
35 |
36 | internal init(target: AnyObject?, attributes: ConstraintAttributes) {
37 | self.target = target
38 | self.attributes = attributes
39 | }
40 |
41 | internal var layoutConstraintItem: LayoutConstraintItem? {
42 | return self.target as? LayoutConstraintItem
43 | }
44 |
45 | }
46 |
47 | public func ==(lhs: ConstraintItem, rhs: ConstraintItem) -> Bool {
48 | // pointer equality
49 | guard lhs !== rhs else {
50 | return true
51 | }
52 |
53 | // must both have valid targets and identical attributes
54 | guard let target1 = lhs.target,
55 | let target2 = rhs.target,
56 | target1 === target2 && lhs.attributes == rhs.attributes else {
57 | return false
58 | }
59 |
60 | return true
61 | }
62 |
--------------------------------------------------------------------------------
/ScanCodeDemo/SnapKit/ConstraintMakerEditable.swift:
--------------------------------------------------------------------------------
1 | //
2 | // SnapKit
3 | //
4 | // Copyright (c) 2011-Present SnapKit Team - https://github.com/SnapKit
5 | //
6 | // Permission is hereby granted, free of charge, to any person obtaining a copy
7 | // of this software and associated documentation files (the "Software"), to deal
8 | // in the Software without restriction, including without limitation the rights
9 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 | // copies of the Software, and to permit persons to whom the Software is
11 | // furnished to do so, subject to the following conditions:
12 | //
13 | // The above copyright notice and this permission notice shall be included in
14 | // all copies or substantial portions of the Software.
15 | //
16 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22 | // THE SOFTWARE.
23 |
24 | #if os(iOS) || os(tvOS)
25 | import UIKit
26 | #else
27 | import AppKit
28 | #endif
29 |
30 |
31 | public class ConstraintMakerEditable: ConstraintMakerPriortizable {
32 |
33 | @discardableResult
34 | public func multipliedBy(_ amount: ConstraintMultiplierTarget) -> ConstraintMakerEditable {
35 | self.description.multiplier = amount
36 | return self
37 | }
38 |
39 | @discardableResult
40 | public func dividedBy(_ amount: ConstraintMultiplierTarget) -> ConstraintMakerEditable {
41 | return self.multipliedBy(1.0 / amount.constraintMultiplierTargetValue)
42 | }
43 |
44 | @discardableResult
45 | public func offset(_ amount: ConstraintOffsetTarget) -> ConstraintMakerEditable {
46 | self.description.constant = amount.constraintOffsetTargetValue
47 | return self
48 | }
49 |
50 | @discardableResult
51 | public func inset(_ amount: ConstraintInsetTarget) -> ConstraintMakerEditable {
52 | self.description.constant = amount.constraintInsetTargetValue
53 | return self
54 | }
55 |
56 | }
57 |
--------------------------------------------------------------------------------
/ScanCodeDemo/SnapKit/ConstraintMultiplierTarget.swift:
--------------------------------------------------------------------------------
1 | //
2 | // SnapKit
3 | //
4 | // Copyright (c) 2011-Present SnapKit Team - https://github.com/SnapKit
5 | //
6 | // Permission is hereby granted, free of charge, to any person obtaining a copy
7 | // of this software and associated documentation files (the "Software"), to deal
8 | // in the Software without restriction, including without limitation the rights
9 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 | // copies of the Software, and to permit persons to whom the Software is
11 | // furnished to do so, subject to the following conditions:
12 | //
13 | // The above copyright notice and this permission notice shall be included in
14 | // all copies or substantial portions of the Software.
15 | //
16 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22 | // THE SOFTWARE.
23 |
24 | #if os(iOS) || os(tvOS)
25 | import UIKit
26 | #else
27 | import AppKit
28 | #endif
29 |
30 |
31 | public protocol ConstraintMultiplierTarget {
32 |
33 | var constraintMultiplierTargetValue: CGFloat { get }
34 |
35 | }
36 |
37 | extension Int: ConstraintMultiplierTarget {
38 |
39 | public var constraintMultiplierTargetValue: CGFloat {
40 | return CGFloat(self)
41 | }
42 |
43 | }
44 |
45 | extension UInt: ConstraintMultiplierTarget {
46 |
47 | public var constraintMultiplierTargetValue: CGFloat {
48 | return CGFloat(self)
49 | }
50 |
51 | }
52 |
53 | extension Float: ConstraintMultiplierTarget {
54 |
55 | public var constraintMultiplierTargetValue: CGFloat {
56 | return CGFloat(self)
57 | }
58 |
59 | }
60 |
61 | extension Double: ConstraintMultiplierTarget {
62 |
63 | public var constraintMultiplierTargetValue: CGFloat {
64 | return CGFloat(self)
65 | }
66 |
67 | }
68 |
69 | extension CGFloat: ConstraintMultiplierTarget {
70 |
71 | public var constraintMultiplierTargetValue: CGFloat {
72 | return self
73 | }
74 |
75 | }
76 |
--------------------------------------------------------------------------------
/ScanCodeDemo/SnapKit/ConstraintOffsetTarget.swift:
--------------------------------------------------------------------------------
1 | //
2 | // SnapKit
3 | //
4 | // Copyright (c) 2011-Present SnapKit Team - https://github.com/SnapKit
5 | //
6 | // Permission is hereby granted, free of charge, to any person obtaining a copy
7 | // of this software and associated documentation files (the "Software"), to deal
8 | // in the Software without restriction, including without limitation the rights
9 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 | // copies of the Software, and to permit persons to whom the Software is
11 | // furnished to do so, subject to the following conditions:
12 | //
13 | // The above copyright notice and this permission notice shall be included in
14 | // all copies or substantial portions of the Software.
15 | //
16 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22 | // THE SOFTWARE.
23 |
24 | #if os(iOS) || os(tvOS)
25 | import UIKit
26 | #else
27 | import AppKit
28 | #endif
29 |
30 |
31 | public protocol ConstraintOffsetTarget: ConstraintConstantTarget {
32 | }
33 |
34 | extension Int: ConstraintOffsetTarget {
35 | }
36 |
37 | extension UInt: ConstraintOffsetTarget {
38 | }
39 |
40 | extension Float: ConstraintOffsetTarget {
41 | }
42 |
43 | extension Double: ConstraintOffsetTarget {
44 | }
45 |
46 | extension CGFloat: ConstraintOffsetTarget {
47 | }
48 |
49 | extension ConstraintOffsetTarget {
50 |
51 | internal var constraintOffsetTargetValue: CGFloat {
52 | let offset: CGFloat
53 | if let amount = self as? Float {
54 | offset = CGFloat(amount)
55 | } else if let amount = self as? Double {
56 | offset = CGFloat(amount)
57 | } else if let amount = self as? CGFloat {
58 | offset = CGFloat(amount)
59 | } else if let amount = self as? Int {
60 | offset = CGFloat(amount)
61 | } else if let amount = self as? UInt {
62 | offset = CGFloat(amount)
63 | } else {
64 | offset = 0.0
65 | }
66 | return offset
67 | }
68 |
69 | }
70 |
--------------------------------------------------------------------------------
/ScanCodeDemo/SnapKit/ConstraintPriorityTarget.swift:
--------------------------------------------------------------------------------
1 | //
2 | // SnapKit
3 | //
4 | // Copyright (c) 2011-Present SnapKit Team - https://github.com/SnapKit
5 | //
6 | // Permission is hereby granted, free of charge, to any person obtaining a copy
7 | // of this software and associated documentation files (the "Software"), to deal
8 | // in the Software without restriction, including without limitation the rights
9 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 | // copies of the Software, and to permit persons to whom the Software is
11 | // furnished to do so, subject to the following conditions:
12 | //
13 | // The above copyright notice and this permission notice shall be included in
14 | // all copies or substantial portions of the Software.
15 | //
16 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22 | // THE SOFTWARE.
23 |
24 | #if os(iOS) || os(tvOS)
25 | import UIKit
26 | #else
27 | import AppKit
28 | #endif
29 |
30 |
31 | public protocol ConstraintPriorityTarget {
32 |
33 | var constraintPriorityTargetValue: Float { get }
34 |
35 | }
36 |
37 | extension Int: ConstraintPriorityTarget {
38 |
39 | public var constraintPriorityTargetValue: Float {
40 | return Float(self)
41 | }
42 |
43 | }
44 |
45 | extension UInt: ConstraintPriorityTarget {
46 |
47 | public var constraintPriorityTargetValue: Float {
48 | return Float(self)
49 | }
50 |
51 | }
52 |
53 | extension Float: ConstraintPriorityTarget {
54 |
55 | public var constraintPriorityTargetValue: Float {
56 | return self
57 | }
58 |
59 | }
60 |
61 | extension Double: ConstraintPriorityTarget {
62 |
63 | public var constraintPriorityTargetValue: Float {
64 | return Float(self)
65 | }
66 |
67 | }
68 |
69 | extension CGFloat: ConstraintPriorityTarget {
70 |
71 | public var constraintPriorityTargetValue: Float {
72 | return Float(self)
73 | }
74 |
75 | }
76 |
77 | #if os(iOS) || os(tvOS)
78 | extension UILayoutPriority: ConstraintPriorityTarget {
79 |
80 | public var constraintPriorityTargetValue: Float {
81 | return self.rawValue
82 | }
83 |
84 | }
85 | #endif
86 |
--------------------------------------------------------------------------------
/ScanCodeDemo/SnapKit/ConstraintLayoutGuideDSL.swift:
--------------------------------------------------------------------------------
1 | //
2 | // SnapKit
3 | //
4 | // Copyright (c) 2011-Present SnapKit Team - https://github.com/SnapKit
5 | //
6 | // Permission is hereby granted, free of charge, to any person obtaining a copy
7 | // of this software and associated documentation files (the "Software"), to deal
8 | // in the Software without restriction, including without limitation the rights
9 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 | // copies of the Software, and to permit persons to whom the Software is
11 | // furnished to do so, subject to the following conditions:
12 | //
13 | // The above copyright notice and this permission notice shall be included in
14 | // all copies or substantial portions of the Software.
15 | //
16 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22 | // THE SOFTWARE.
23 |
24 | #if os(iOS) || os(tvOS)
25 | import UIKit
26 | #else
27 | import AppKit
28 | #endif
29 |
30 |
31 | @available(iOS 9.0, OSX 10.11, *)
32 | public struct ConstraintLayoutGuideDSL: ConstraintAttributesDSL {
33 |
34 | @discardableResult
35 | public func prepareConstraints(_ closure: (_ make: ConstraintMaker) -> Void) -> [Constraint] {
36 | return ConstraintMaker.prepareConstraints(item: self.guide, closure: closure)
37 | }
38 |
39 | public func makeConstraints(_ closure: (_ make: ConstraintMaker) -> Void) {
40 | ConstraintMaker.makeConstraints(item: self.guide, closure: closure)
41 | }
42 |
43 | public func remakeConstraints(_ closure: (_ make: ConstraintMaker) -> Void) {
44 | ConstraintMaker.remakeConstraints(item: self.guide, closure: closure)
45 | }
46 |
47 | public func updateConstraints(_ closure: (_ make: ConstraintMaker) -> Void) {
48 | ConstraintMaker.updateConstraints(item: self.guide, closure: closure)
49 | }
50 |
51 | public func removeConstraints() {
52 | ConstraintMaker.removeConstraints(item: self.guide)
53 | }
54 |
55 | public var target: AnyObject? {
56 | return self.guide
57 | }
58 |
59 | internal let guide: ConstraintLayoutGuide
60 |
61 | internal init(guide: ConstraintLayoutGuide) {
62 | self.guide = guide
63 |
64 | }
65 |
66 | }
67 |
--------------------------------------------------------------------------------
/ScanCodeDemo/SnapKit/ConstraintPriority.swift:
--------------------------------------------------------------------------------
1 | //
2 | // SnapKit
3 | //
4 | // Copyright (c) 2011-Present SnapKit Team - https://github.com/SnapKit
5 | //
6 | // Permission is hereby granted, free of charge, to any person obtaining a copy
7 | // of this software and associated documentation files (the "Software"), to deal
8 | // in the Software without restriction, including without limitation the rights
9 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 | // copies of the Software, and to permit persons to whom the Software is
11 | // furnished to do so, subject to the following conditions:
12 | //
13 | // The above copyright notice and this permission notice shall be included in
14 | // all copies or substantial portions of the Software.
15 | //
16 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22 | // THE SOFTWARE.
23 |
24 | #if os(iOS) || os(tvOS)
25 | import UIKit
26 | #else
27 | import AppKit
28 | #endif
29 |
30 | public struct ConstraintPriority : ExpressibleByFloatLiteral, Equatable, Strideable {
31 | public typealias FloatLiteralType = Float
32 |
33 | public let value: Float
34 |
35 | public init(floatLiteral value: Float) {
36 | self.value = value
37 | }
38 |
39 | public init(_ value: Float) {
40 | self.value = value
41 | }
42 |
43 | public static var required: ConstraintPriority {
44 | return 1000.0
45 | }
46 |
47 | public static var high: ConstraintPriority {
48 | return 750.0
49 | }
50 |
51 | public static var medium: ConstraintPriority {
52 | #if os(OSX)
53 | return 501.0
54 | #else
55 | return 500.0
56 | #endif
57 |
58 | }
59 |
60 | public static var low: ConstraintPriority {
61 | return 250.0
62 | }
63 |
64 | public static func ==(lhs: ConstraintPriority, rhs: ConstraintPriority) -> Bool {
65 | return lhs.value == rhs.value
66 | }
67 |
68 | // MARK: Strideable
69 |
70 | public func advanced(by n: FloatLiteralType) -> ConstraintPriority {
71 | return ConstraintPriority(floatLiteral: value + n)
72 | }
73 |
74 | public func distance(to other: ConstraintPriority) -> FloatLiteralType {
75 | return other.value - value
76 | }
77 | }
78 |
--------------------------------------------------------------------------------
/ScanCodeDemo/SnapKit/ConstraintMakerPriortizable.swift:
--------------------------------------------------------------------------------
1 | //
2 | // SnapKit
3 | //
4 | // Copyright (c) 2011-Present SnapKit Team - https://github.com/SnapKit
5 | //
6 | // Permission is hereby granted, free of charge, to any person obtaining a copy
7 | // of this software and associated documentation files (the "Software"), to deal
8 | // in the Software without restriction, including without limitation the rights
9 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 | // copies of the Software, and to permit persons to whom the Software is
11 | // furnished to do so, subject to the following conditions:
12 | //
13 | // The above copyright notice and this permission notice shall be included in
14 | // all copies or substantial portions of the Software.
15 | //
16 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22 | // THE SOFTWARE.
23 |
24 | #if os(iOS) || os(tvOS)
25 | import UIKit
26 | #else
27 | import AppKit
28 | #endif
29 |
30 |
31 | public class ConstraintMakerPriortizable: ConstraintMakerFinalizable {
32 |
33 | @discardableResult
34 | public func priority(_ amount: ConstraintPriority) -> ConstraintMakerFinalizable {
35 | self.description.priority = amount.value
36 | return self
37 | }
38 |
39 | @discardableResult
40 | public func priority(_ amount: ConstraintPriorityTarget) -> ConstraintMakerFinalizable {
41 | self.description.priority = amount
42 | return self
43 | }
44 |
45 | @available(*, deprecated:3.0, message:"Use priority(.required) instead.")
46 | @discardableResult
47 | public func priorityRequired() -> ConstraintMakerFinalizable {
48 | return self.priority(.required)
49 | }
50 |
51 | @available(*, deprecated:3.0, message:"Use priority(.high) instead.")
52 | @discardableResult
53 | public func priorityHigh() -> ConstraintMakerFinalizable {
54 | return self.priority(.high)
55 | }
56 |
57 | @available(*, deprecated:3.0, message:"Use priority(.medium) instead.")
58 | @discardableResult
59 | public func priorityMedium() -> ConstraintMakerFinalizable {
60 | return self.priority(.medium)
61 | }
62 |
63 | @available(*, deprecated:3.0, message:"Use priority(.low) instead.")
64 | @discardableResult
65 | public func priorityLow() -> ConstraintMakerFinalizable {
66 | return self.priority(.low)
67 | }
68 | }
69 |
--------------------------------------------------------------------------------
/ScanCodeDemo/SnapKit/ConstraintDescription.swift:
--------------------------------------------------------------------------------
1 | //
2 | // SnapKit
3 | //
4 | // Copyright (c) 2011-Present SnapKit Team - https://github.com/SnapKit
5 | //
6 | // Permission is hereby granted, free of charge, to any person obtaining a copy
7 | // of this software and associated documentation files (the "Software"), to deal
8 | // in the Software without restriction, including without limitation the rights
9 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 | // copies of the Software, and to permit persons to whom the Software is
11 | // furnished to do so, subject to the following conditions:
12 | //
13 | // The above copyright notice and this permission notice shall be included in
14 | // all copies or substantial portions of the Software.
15 | //
16 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22 | // THE SOFTWARE.
23 |
24 | #if os(iOS) || os(tvOS)
25 | import UIKit
26 | #else
27 | import AppKit
28 | #endif
29 |
30 |
31 | public class ConstraintDescription {
32 |
33 | internal let item: LayoutConstraintItem
34 | internal var attributes: ConstraintAttributes
35 | internal var relation: ConstraintRelation? = nil
36 | internal var sourceLocation: (String, UInt)? = nil
37 | internal var label: String? = nil
38 | internal var related: ConstraintItem? = nil
39 | internal var multiplier: ConstraintMultiplierTarget = 1.0
40 | internal var constant: ConstraintConstantTarget = 0.0
41 | internal var priority: ConstraintPriorityTarget = 1000.0
42 | internal lazy var constraint: Constraint? = {
43 | guard let relation = self.relation,
44 | let related = self.related,
45 | let sourceLocation = self.sourceLocation else {
46 | return nil
47 | }
48 | let from = ConstraintItem(target: self.item, attributes: self.attributes)
49 |
50 | return Constraint(
51 | from: from,
52 | to: related,
53 | relation: relation,
54 | sourceLocation: sourceLocation,
55 | label: self.label,
56 | multiplier: self.multiplier,
57 | constant: self.constant,
58 | priority: self.priority
59 | )
60 | }()
61 |
62 | // MARK: Initialization
63 |
64 | internal init(item: LayoutConstraintItem, attributes: ConstraintAttributes) {
65 | self.item = item
66 | self.attributes = attributes
67 | }
68 |
69 | }
70 |
--------------------------------------------------------------------------------
/ScanCodeDemo/ViewController.swift:
--------------------------------------------------------------------------------
1 | //
2 | // ViewController.swift
3 | // ScanCodeDemo
4 | //
5 | // Created by YTiOSer on 18/5.
6 | // Copyright © 2018 YTiOSer. All rights reserved.
7 | //
8 |
9 | import UIKit
10 |
11 | class ViewController: UIViewController {
12 |
13 | fileprivate var label_Type: UILabel! //类型
14 | fileprivate var label_Content: UILabel! //扫码结果
15 |
16 | override func viewDidLoad() {
17 | super.viewDidLoad()
18 |
19 | initMainView()
20 | }
21 |
22 | override func didReceiveMemoryWarning() {
23 | super.didReceiveMemoryWarning()
24 | // Dispose of any resources that can be recreated.
25 | }
26 |
27 |
28 | }
29 |
30 |
31 | extension ViewController{
32 |
33 | @objc func codeScan() {
34 |
35 | let controller = YTScanCodeViewController()
36 | present(controller, animated: true, completion: nil)
37 | controller.setBackClosure { [unowned self] (type, code) -> Void in
38 | self.label_Content.text = "code: \(code)"
39 | if type == "vin"{
40 | self.label_Type.text = "类型: VIN"
41 | }else if type == "oem"{
42 | self.label_Type.text = "类型: 二维码"
43 | }
44 | }
45 |
46 | }
47 |
48 | }
49 |
50 | // MARK: UI
51 | extension ViewController{
52 |
53 | func initMainView() {
54 |
55 | let btn = UIButton.init(type: .custom)
56 | btn.setTitle("扫码", for: .normal)
57 | btn.setTitleColor(UIColor.orange, for: .normal)
58 | btn.titleLabel?.font = UIFont.systemFont(ofSize: 18)
59 | btn.layer.borderWidth = 1
60 | btn.layer.borderColor = UIColor.orange.cgColor
61 | btn.addTarget(self, action: #selector(codeScan), for: .touchUpInside)
62 | view.addSubview(btn)
63 | btn.snp.makeConstraints { (make) in
64 | make.left.equalTo(13)
65 | make.right.equalTo(-13)
66 | make.top.equalTo(200)
67 | make.height.equalTo(50)
68 | }
69 |
70 | label_Type = createCustomLabel(content: "类型: ")
71 | view.addSubview(label_Type)
72 | label_Type.snp.makeConstraints { (make) in
73 | make.left.right.equalTo(btn)
74 | make.top.equalTo(btn.snp.bottom).offset(50)
75 | make.height.equalTo(25)
76 | }
77 |
78 | label_Content = createCustomLabel(content: "code: ")
79 | view.addSubview(label_Content)
80 | label_Content.snp.makeConstraints { (make) in
81 | make.left.right.height.equalTo(label_Type)
82 | make.top.equalTo(label_Type.snp.bottom).offset(20)
83 | }
84 |
85 | }
86 |
87 | func createCustomLabel(content: String) -> UILabel {
88 | let label = UILabel()
89 | label.text = content
90 | label.textColor = UIColor.gray
91 | label.font = UIFont.systemFont(ofSize: 15)
92 | label.sizeToFit()
93 | return label
94 | }
95 |
96 | }
97 |
98 |
--------------------------------------------------------------------------------
/ScanCodeDemo/SnapKit/ConstraintInsetTarget.swift:
--------------------------------------------------------------------------------
1 | //
2 | // SnapKit
3 | //
4 | // Copyright (c) 2011-Present SnapKit Team - https://github.com/SnapKit
5 | //
6 | // Permission is hereby granted, free of charge, to any person obtaining a copy
7 | // of this software and associated documentation files (the "Software"), to deal
8 | // in the Software without restriction, including without limitation the rights
9 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 | // copies of the Software, and to permit persons to whom the Software is
11 | // furnished to do so, subject to the following conditions:
12 | //
13 | // The above copyright notice and this permission notice shall be included in
14 | // all copies or substantial portions of the Software.
15 | //
16 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22 | // THE SOFTWARE.
23 |
24 | #if os(iOS) || os(tvOS)
25 | import UIKit
26 | #else
27 | import AppKit
28 | #endif
29 |
30 |
31 | public protocol ConstraintInsetTarget: ConstraintConstantTarget {
32 | }
33 |
34 | extension Int: ConstraintInsetTarget {
35 | }
36 |
37 | extension UInt: ConstraintInsetTarget {
38 | }
39 |
40 | extension Float: ConstraintInsetTarget {
41 | }
42 |
43 | extension Double: ConstraintInsetTarget {
44 | }
45 |
46 | extension CGFloat: ConstraintInsetTarget {
47 | }
48 |
49 | extension ConstraintInsets: ConstraintInsetTarget {
50 | }
51 |
52 | extension ConstraintInsetTarget {
53 |
54 | internal var constraintInsetTargetValue: ConstraintInsets {
55 | if let amount = self as? ConstraintInsets {
56 | return amount
57 | } else if let amount = self as? Float {
58 | return ConstraintInsets(top: CGFloat(amount), left: CGFloat(amount), bottom: CGFloat(amount), right: CGFloat(amount))
59 | } else if let amount = self as? Double {
60 | return ConstraintInsets(top: CGFloat(amount), left: CGFloat(amount), bottom: CGFloat(amount), right: CGFloat(amount))
61 | } else if let amount = self as? CGFloat {
62 | return ConstraintInsets(top: amount, left: amount, bottom: amount, right: amount)
63 | } else if let amount = self as? Int {
64 | return ConstraintInsets(top: CGFloat(amount), left: CGFloat(amount), bottom: CGFloat(amount), right: CGFloat(amount))
65 | } else if let amount = self as? UInt {
66 | return ConstraintInsets(top: CGFloat(amount), left: CGFloat(amount), bottom: CGFloat(amount), right: CGFloat(amount))
67 | } else {
68 | return ConstraintInsets(top: 0, left: 0, bottom: 0, right: 0)
69 | }
70 | }
71 |
72 | }
73 |
--------------------------------------------------------------------------------
/ScanCodeDemo/SnapKit/LayoutConstraintItem.swift:
--------------------------------------------------------------------------------
1 | //
2 | // SnapKit
3 | //
4 | // Copyright (c) 2011-Present SnapKit Team - https://github.com/SnapKit
5 | //
6 | // Permission is hereby granted, free of charge, to any person obtaining a copy
7 | // of this software and associated documentation files (the "Software"), to deal
8 | // in the Software without restriction, including without limitation the rights
9 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 | // copies of the Software, and to permit persons to whom the Software is
11 | // furnished to do so, subject to the following conditions:
12 | //
13 | // The above copyright notice and this permission notice shall be included in
14 | // all copies or substantial portions of the Software.
15 | //
16 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22 | // THE SOFTWARE.
23 |
24 | #if os(iOS) || os(tvOS)
25 | import UIKit
26 | #else
27 | import AppKit
28 | #endif
29 |
30 |
31 | public protocol LayoutConstraintItem: class {
32 | }
33 |
34 | @available(iOS 9.0, OSX 10.11, *)
35 | extension ConstraintLayoutGuide : LayoutConstraintItem {
36 | }
37 |
38 | extension ConstraintView : LayoutConstraintItem {
39 | }
40 |
41 |
42 | extension LayoutConstraintItem {
43 |
44 | internal func prepare() {
45 | if let view = self as? ConstraintView {
46 | view.translatesAutoresizingMaskIntoConstraints = false
47 | }
48 | }
49 |
50 | internal var superview: ConstraintView? {
51 | if let view = self as? ConstraintView {
52 | return view.superview
53 | }
54 |
55 | if #available(iOS 9.0, OSX 10.11, *), let guide = self as? ConstraintLayoutGuide {
56 | return guide.owningView
57 | }
58 |
59 | return nil
60 | }
61 | internal var constraints: [Constraint] {
62 | return self.constraintsSet.allObjects as! [Constraint]
63 | }
64 |
65 | internal func add(constraints: [Constraint]) {
66 | let constraintsSet = self.constraintsSet
67 | for constraint in constraints {
68 | constraintsSet.add(constraint)
69 | }
70 | }
71 |
72 | internal func remove(constraints: [Constraint]) {
73 | let constraintsSet = self.constraintsSet
74 | for constraint in constraints {
75 | constraintsSet.remove(constraint)
76 | }
77 | }
78 |
79 | private var constraintsSet: NSMutableSet {
80 | let constraintsSet: NSMutableSet
81 |
82 | if let existing = objc_getAssociatedObject(self, &constraintsKey) as? NSMutableSet {
83 | constraintsSet = existing
84 | } else {
85 | constraintsSet = NSMutableSet()
86 | objc_setAssociatedObject(self, &constraintsKey, constraintsSet, .OBJC_ASSOCIATION_RETAIN_NONATOMIC)
87 | }
88 | return constraintsSet
89 |
90 | }
91 |
92 | }
93 | private var constraintsKey: UInt8 = 0
94 |
--------------------------------------------------------------------------------
/ScanCodeDemo/SnapKit/ConstraintViewDSL.swift:
--------------------------------------------------------------------------------
1 | //
2 | // SnapKit
3 | //
4 | // Copyright (c) 2011-Present SnapKit Team - https://github.com/SnapKit
5 | //
6 | // Permission is hereby granted, free of charge, to any person obtaining a copy
7 | // of this software and associated documentation files (the "Software"), to deal
8 | // in the Software without restriction, including without limitation the rights
9 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 | // copies of the Software, and to permit persons to whom the Software is
11 | // furnished to do so, subject to the following conditions:
12 | //
13 | // The above copyright notice and this permission notice shall be included in
14 | // all copies or substantial portions of the Software.
15 | //
16 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22 | // THE SOFTWARE.
23 |
24 | #if os(iOS) || os(tvOS)
25 | import UIKit
26 | #else
27 | import AppKit
28 | #endif
29 |
30 |
31 | public struct ConstraintViewDSL: ConstraintAttributesDSL {
32 |
33 | @discardableResult
34 | public func prepareConstraints(_ closure: (_ make: ConstraintMaker) -> Void) -> [Constraint] {
35 | return ConstraintMaker.prepareConstraints(item: self.view, closure: closure)
36 | }
37 |
38 | public func makeConstraints(_ closure: (_ make: ConstraintMaker) -> Void) {
39 | ConstraintMaker.makeConstraints(item: self.view, closure: closure)
40 | }
41 |
42 | public func remakeConstraints(_ closure: (_ make: ConstraintMaker) -> Void) {
43 | ConstraintMaker.remakeConstraints(item: self.view, closure: closure)
44 | }
45 |
46 | public func updateConstraints(_ closure: (_ make: ConstraintMaker) -> Void) {
47 | ConstraintMaker.updateConstraints(item: self.view, closure: closure)
48 | }
49 |
50 | public func removeConstraints() {
51 | ConstraintMaker.removeConstraints(item: self.view)
52 | }
53 |
54 | public var contentHuggingHorizontalPriority: Float {
55 | get {
56 | return self.view.contentHuggingPriority(for: .horizontal).rawValue
57 | }
58 | set {
59 | self.view.setContentHuggingPriority(LayoutPriority(rawValue: newValue), for: .horizontal)
60 | }
61 | }
62 |
63 | public var contentHuggingVerticalPriority: Float {
64 | get {
65 | return self.view.contentHuggingPriority(for: .vertical).rawValue
66 | }
67 | set {
68 | self.view.setContentHuggingPriority(LayoutPriority(rawValue: newValue), for: .vertical)
69 | }
70 | }
71 |
72 | public var contentCompressionResistanceHorizontalPriority: Float {
73 | get {
74 | return self.view.contentCompressionResistancePriority(for: .horizontal).rawValue
75 | }
76 | set {
77 | self.view.setContentCompressionResistancePriority(LayoutPriority(rawValue: newValue), for: .horizontal)
78 | }
79 | }
80 |
81 | public var contentCompressionResistanceVerticalPriority: Float {
82 | get {
83 | return self.view.contentCompressionResistancePriority(for: .vertical).rawValue
84 | }
85 | set {
86 | self.view.setContentCompressionResistancePriority(LayoutPriority(rawValue: newValue), for: .vertical)
87 | }
88 | }
89 |
90 | public var target: AnyObject? {
91 | return self.view
92 | }
93 |
94 | internal let view: ConstraintView
95 |
96 | internal init(view: ConstraintView) {
97 | self.view = view
98 |
99 | }
100 |
101 | }
102 |
--------------------------------------------------------------------------------
/ScanCodeDemo/base/QGToast.swift:
--------------------------------------------------------------------------------
1 | //
2 | // QGToast.swift
3 | // B2BAutoziMall
4 | //
5 | // Created by YTiOSer on 18/5.
6 | // Copyright © 2018 YTiOSer. All rights reserved.
7 | //
8 |
9 | import UIKit
10 |
11 | // 枚举类型
12 | enum iToastGravity:Int{
13 | case top = 1000001
14 | case bottom
15 | case center
16 | func typeName() -> String {
17 | return "iToastGravity"
18 | }
19 | }
20 |
21 | class ToastSettingClass:NSObject {
22 |
23 | var textFont:CGFloat
24 | var duration:CGFloat
25 | var position:iToastGravity
26 |
27 | override init(){
28 | textFont = 14
29 | duration = 2
30 | position = iToastGravity.bottom
31 | super.init()
32 | }
33 | }
34 |
35 | class QGToast: NSObject {
36 | var toastSetting:ToastSettingClass!
37 | var frameMarginSize:CGFloat! = 10
38 | var frameSize:CGSize = CGSize(width: kScreenW - 40, height: 265)
39 | var view:UIView!
40 |
41 |
42 | /// 初始化
43 | ///
44 | /// 提示
45 | ///
46 | /// QGToast(text:String,duration:TimeInterval)
47 | ///
48 | /// - Parameter text: 提示信息.
49 | /// - Parameter duration: 显示多长时间.
50 | ///
51 | /// - Returns: QGToast.
52 | ///
53 | /// - Complexity: O(*n*), where *n* is the number of elements to drop.
54 |
55 | init(text:String,duration:TimeInterval) {
56 | super.init()
57 | toastSetting = ToastSettingClass()
58 | let textFont = toastSetting.textFont
59 | let size:CGSize = self.sizeWithString(text as NSString, font: UIFont.systemFont(ofSize: textFont))
60 |
61 | let label:UILabel = UILabel (frame: CGRect(x: 0, y: 0, width: size.width, height: size.height))
62 | label.text = text
63 | label.font = UIFont.systemFont(ofSize: textFont)
64 | label.numberOfLines = 0;
65 | label.textColor = UIColor.white
66 |
67 | var window:UIWindow = findLastWindowInScreen()
68 | if #available(iOS 11.0, *) {
69 | window = findFirstWindowInScreen()
70 | }
71 |
72 | let v:UIButton = UIButton(frame:CGRect(x: 0, y: 0, width: size.width + frameMarginSize, height: size.height + frameMarginSize))
73 | label.center = CGPoint(x: v.frame.size.width / 2, y: v.frame.size.height / 2);
74 | v.addSubview(label)
75 |
76 | v.backgroundColor = UIColor(red: 0, green: 0, blue: 0, alpha: 0.7)
77 | v.layer.cornerRadius = 5
78 | var point:CGPoint = CGPoint(x: window.frame.size.width/2, y: window.frame.size.height/5*4);
79 | point = CGPoint(x: point.x , y: point.y + 10);
80 | v.center = point
81 |
82 | window.addSubview(v)
83 | view = v
84 |
85 | v.addTarget(self, action: #selector(QGToast.hideToast), for: UIControlEvents.touchDown)
86 | let timer:Timer = Timer(timeInterval: duration, target: self, selector: #selector(QGToast.hideToast), userInfo: nil, repeats: false)
87 | RunLoop.main.add(timer, forMode: RunLoopMode.defaultRunLoopMode)
88 | }
89 |
90 | func sizeWithString(_ string:NSString, font:UIFont)-> CGSize {
91 | let options = NSStringDrawingOptions.usesLineFragmentOrigin
92 | let rect:CGRect = string.boundingRect(with: frameSize, options:options, attributes: [NSAttributedStringKey(rawValue: "NSFontAttributeName"): font], context: nil)
93 | return rect.size
94 | }
95 |
96 | @objc func hideToast(){
97 | UIView.animate(withDuration: 0.2, animations: {
98 | () -> ()in
99 | self.view.alpha = 0
100 | }, completion: {
101 | (Boolean) -> ()in
102 | self.view.removeFromSuperview()
103 | })
104 |
105 | }
106 |
107 | required init(coder aDecoder: NSCoder) {
108 | fatalError("init(coder:) has not been implemented")
109 | }
110 | }
111 |
112 | let kScreenBounds = UIScreen.main.bounds
113 |
114 | func findLastWindowInScreen() -> UIWindow {
115 | let windows = UIApplication.shared.windows
116 | let windowCount = windows.count
117 | var windowTemp = UIWindow()
118 | for i in 0.. UIWindow {
125 | let windows = UIApplication.shared.windows
126 | let windowCount = windows.count
127 | var windowTemp = UIWindow()
128 | for i in 0.. ConstraintMakerEditable {
40 | let related: ConstraintItem
41 | let constant: ConstraintConstantTarget
42 |
43 | if let other = other as? ConstraintItem {
44 | guard other.attributes == ConstraintAttributes.none ||
45 | other.attributes.layoutAttributes.count <= 1 ||
46 | other.attributes.layoutAttributes == self.description.attributes.layoutAttributes ||
47 | other.attributes == .edges && self.description.attributes == .margins ||
48 | other.attributes == .margins && self.description.attributes == .edges else {
49 | fatalError("Cannot constraint to multiple non identical attributes. (\(file), \(line))");
50 | }
51 |
52 | related = other
53 | constant = 0.0
54 | } else if let other = other as? ConstraintView {
55 | related = ConstraintItem(target: other, attributes: ConstraintAttributes.none)
56 | constant = 0.0
57 | } else if let other = other as? ConstraintConstantTarget {
58 | related = ConstraintItem(target: nil, attributes: ConstraintAttributes.none)
59 | constant = other
60 | } else if #available(iOS 9.0, OSX 10.11, *), let other = other as? ConstraintLayoutGuide {
61 | related = ConstraintItem(target: other, attributes: ConstraintAttributes.none)
62 | constant = 0.0
63 | } else {
64 | fatalError("Invalid constraint. (\(file), \(line))")
65 | }
66 |
67 | let editable = ConstraintMakerEditable(self.description)
68 | editable.description.sourceLocation = (file, line)
69 | editable.description.relation = relation
70 | editable.description.related = related
71 | editable.description.constant = constant
72 | return editable
73 | }
74 |
75 | @discardableResult
76 | public func equalTo(_ other: ConstraintRelatableTarget, _ file: String = #file, _ line: UInt = #line) -> ConstraintMakerEditable {
77 | return self.relatedTo(other, relation: .equal, file: file, line: line)
78 | }
79 |
80 | @discardableResult
81 | public func equalToSuperview(_ file: String = #file, _ line: UInt = #line) -> ConstraintMakerEditable {
82 | guard let other = self.description.item.superview else {
83 | fatalError("Expected superview but found nil when attempting make constraint `equalToSuperview`.")
84 | }
85 | return self.relatedTo(other, relation: .equal, file: file, line: line)
86 | }
87 |
88 | @discardableResult
89 | public func lessThanOrEqualTo(_ other: ConstraintRelatableTarget, _ file: String = #file, _ line: UInt = #line) -> ConstraintMakerEditable {
90 | return self.relatedTo(other, relation: .lessThanOrEqual, file: file, line: line)
91 | }
92 |
93 | @discardableResult
94 | public func lessThanOrEqualToSuperview(_ file: String = #file, _ line: UInt = #line) -> ConstraintMakerEditable {
95 | guard let other = self.description.item.superview else {
96 | fatalError("Expected superview but found nil when attempting make constraint `lessThanOrEqualToSuperview`.")
97 | }
98 | return self.relatedTo(other, relation: .lessThanOrEqual, file: file, line: line)
99 | }
100 |
101 | @discardableResult
102 | public func greaterThanOrEqualTo(_ other: ConstraintRelatableTarget, _ file: String = #file, line: UInt = #line) -> ConstraintMakerEditable {
103 | return self.relatedTo(other, relation: .greaterThanOrEqual, file: file, line: line)
104 | }
105 |
106 | @discardableResult
107 | public func greaterThanOrEqualToSuperview(_ file: String = #file, line: UInt = #line) -> ConstraintMakerEditable {
108 | guard let other = self.description.item.superview else {
109 | fatalError("Expected superview but found nil when attempting make constraint `greaterThanOrEqualToSuperview`.")
110 | }
111 | return self.relatedTo(other, relation: .greaterThanOrEqual, file: file, line: line)
112 | }
113 | }
114 |
--------------------------------------------------------------------------------
/ScanCodeDemo/SnapKit/ConstraintMakerExtendable.swift:
--------------------------------------------------------------------------------
1 | //
2 | // SnapKit
3 | //
4 | // Copyright (c) 2011-Present SnapKit Team - https://github.com/SnapKit
5 | //
6 | // Permission is hereby granted, free of charge, to any person obtaining a copy
7 | // of this software and associated documentation files (the "Software"), to deal
8 | // in the Software without restriction, including without limitation the rights
9 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 | // copies of the Software, and to permit persons to whom the Software is
11 | // furnished to do so, subject to the following conditions:
12 | //
13 | // The above copyright notice and this permission notice shall be included in
14 | // all copies or substantial portions of the Software.
15 | //
16 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22 | // THE SOFTWARE.
23 |
24 | #if os(iOS) || os(tvOS)
25 | import UIKit
26 | #else
27 | import AppKit
28 | #endif
29 |
30 |
31 | public class ConstraintMakerExtendable: ConstraintMakerRelatable {
32 |
33 | public var left: ConstraintMakerExtendable {
34 | self.description.attributes += .left
35 | return self
36 | }
37 |
38 | public var top: ConstraintMakerExtendable {
39 | self.description.attributes += .top
40 | return self
41 | }
42 |
43 | public var bottom: ConstraintMakerExtendable {
44 | self.description.attributes += .bottom
45 | return self
46 | }
47 |
48 | public var right: ConstraintMakerExtendable {
49 | self.description.attributes += .right
50 | return self
51 | }
52 |
53 | public var leading: ConstraintMakerExtendable {
54 | self.description.attributes += .leading
55 | return self
56 | }
57 |
58 | public var trailing: ConstraintMakerExtendable {
59 | self.description.attributes += .trailing
60 | return self
61 | }
62 |
63 | public var width: ConstraintMakerExtendable {
64 | self.description.attributes += .width
65 | return self
66 | }
67 |
68 | public var height: ConstraintMakerExtendable {
69 | self.description.attributes += .height
70 | return self
71 | }
72 |
73 | public var centerX: ConstraintMakerExtendable {
74 | self.description.attributes += .centerX
75 | return self
76 | }
77 |
78 | public var centerY: ConstraintMakerExtendable {
79 | self.description.attributes += .centerY
80 | return self
81 | }
82 |
83 | @available(*, deprecated:3.0, message:"Use lastBaseline instead")
84 | public var baseline: ConstraintMakerExtendable {
85 | self.description.attributes += .lastBaseline
86 | return self
87 | }
88 |
89 | public var lastBaseline: ConstraintMakerExtendable {
90 | self.description.attributes += .lastBaseline
91 | return self
92 | }
93 |
94 | @available(iOS 8.0, OSX 10.11, *)
95 | public var firstBaseline: ConstraintMakerExtendable {
96 | self.description.attributes += .firstBaseline
97 | return self
98 | }
99 |
100 | @available(iOS 8.0, *)
101 | public var leftMargin: ConstraintMakerExtendable {
102 | self.description.attributes += .leftMargin
103 | return self
104 | }
105 |
106 | @available(iOS 8.0, *)
107 | public var rightMargin: ConstraintMakerExtendable {
108 | self.description.attributes += .rightMargin
109 | return self
110 | }
111 |
112 | @available(iOS 8.0, *)
113 | public var topMargin: ConstraintMakerExtendable {
114 | self.description.attributes += .topMargin
115 | return self
116 | }
117 |
118 | @available(iOS 8.0, *)
119 | public var bottomMargin: ConstraintMakerExtendable {
120 | self.description.attributes += .bottomMargin
121 | return self
122 | }
123 |
124 | @available(iOS 8.0, *)
125 | public var leadingMargin: ConstraintMakerExtendable {
126 | self.description.attributes += .leadingMargin
127 | return self
128 | }
129 |
130 | @available(iOS 8.0, *)
131 | public var trailingMargin: ConstraintMakerExtendable {
132 | self.description.attributes += .trailingMargin
133 | return self
134 | }
135 |
136 | @available(iOS 8.0, *)
137 | public var centerXWithinMargins: ConstraintMakerExtendable {
138 | self.description.attributes += .centerXWithinMargins
139 | return self
140 | }
141 |
142 | @available(iOS 8.0, *)
143 | public var centerYWithinMargins: ConstraintMakerExtendable {
144 | self.description.attributes += .centerYWithinMargins
145 | return self
146 | }
147 |
148 | public var edges: ConstraintMakerExtendable {
149 | self.description.attributes += .edges
150 | return self
151 | }
152 | public var size: ConstraintMakerExtendable {
153 | self.description.attributes += .size
154 | return self
155 | }
156 |
157 | @available(iOS 8.0, *)
158 | public var margins: ConstraintMakerExtendable {
159 | self.description.attributes += .margins
160 | return self
161 | }
162 |
163 | @available(iOS 8.0, *)
164 | public var centerWithinMargins: ConstraintMakerExtendable {
165 | self.description.attributes += .centerWithinMargins
166 | return self
167 | }
168 |
169 | }
170 |
--------------------------------------------------------------------------------
/ScanCodeDemo/SnapKit/ConstraintConstantTarget.swift:
--------------------------------------------------------------------------------
1 | //
2 | // SnapKit
3 | //
4 | // Copyright (c) 2011-Present SnapKit Team - https://github.com/SnapKit
5 | //
6 | // Permission is hereby granted, free of charge, to any person obtaining a copy
7 | // of this software and associated documentation files (the "Software"), to deal
8 | // in the Software without restriction, including without limitation the rights
9 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 | // copies of the Software, and to permit persons to whom the Software is
11 | // furnished to do so, subject to the following conditions:
12 | //
13 | // The above copyright notice and this permission notice shall be included in
14 | // all copies or substantial portions of the Software.
15 | //
16 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22 | // THE SOFTWARE.
23 |
24 | #if os(iOS) || os(tvOS)
25 | import UIKit
26 | #else
27 | import AppKit
28 | #endif
29 |
30 |
31 | public protocol ConstraintConstantTarget {
32 | }
33 |
34 | extension CGPoint: ConstraintConstantTarget {
35 | }
36 |
37 | extension CGSize: ConstraintConstantTarget {
38 | }
39 |
40 | extension ConstraintInsets: ConstraintConstantTarget {
41 | }
42 |
43 | extension ConstraintConstantTarget {
44 |
45 | internal func constraintConstantTargetValueFor(layoutAttribute: LayoutAttribute) -> CGFloat {
46 | if let value = self as? CGFloat {
47 | return value
48 | }
49 |
50 | if let value = self as? Float {
51 | return CGFloat(value)
52 | }
53 |
54 | if let value = self as? Double {
55 | return CGFloat(value)
56 | }
57 |
58 | if let value = self as? Int {
59 | return CGFloat(value)
60 | }
61 |
62 | if let value = self as? UInt {
63 | return CGFloat(value)
64 | }
65 |
66 | if let value = self as? CGSize {
67 | if layoutAttribute == .width {
68 | return value.width
69 | } else if layoutAttribute == .height {
70 | return value.height
71 | } else {
72 | return 0.0
73 | }
74 | }
75 |
76 | if let value = self as? CGPoint {
77 | #if os(iOS) || os(tvOS)
78 | switch layoutAttribute {
79 | case .left, .right, .leading, .trailing, .centerX, .leftMargin, .rightMargin, .leadingMargin, .trailingMargin, .centerXWithinMargins:
80 | return value.x
81 | case .top, .bottom, .centerY, .topMargin, .bottomMargin, .centerYWithinMargins, .lastBaseline, .firstBaseline:
82 | return value.y
83 | case .width, .height, .notAnAttribute:
84 | return 0.0
85 | }
86 | #else
87 | switch layoutAttribute {
88 | case .left, .right, .leading, .trailing, .centerX:
89 | return value.x
90 | case .top, .bottom, .centerY, .lastBaseline, .firstBaseline:
91 | return value.y
92 | case .width, .height, .notAnAttribute:
93 | return 0.0
94 | }
95 | #endif
96 | }
97 |
98 | if let value = self as? ConstraintInsets {
99 | #if os(iOS) || os(tvOS)
100 | switch layoutAttribute {
101 | case .left, .leftMargin, .centerX, .centerXWithinMargins:
102 | return value.left
103 | case .top, .topMargin, .centerY, .centerYWithinMargins, .lastBaseline, .firstBaseline:
104 | return value.top
105 | case .right, .rightMargin:
106 | return -value.right
107 | case .bottom, .bottomMargin:
108 | return -value.bottom
109 | case .leading, .leadingMargin:
110 | return (ConstraintConfig.interfaceLayoutDirection == .leftToRight) ? value.left : value.right
111 | case .trailing, .trailingMargin:
112 | return (ConstraintConfig.interfaceLayoutDirection == .leftToRight) ? -value.right : -value.left
113 | case .width:
114 | return -(value.left + value.right)
115 | case .height:
116 | return -(value.top + value.bottom)
117 | case .notAnAttribute:
118 | return 0.0
119 | }
120 | #else
121 | switch layoutAttribute {
122 | case .left, .centerX:
123 | return value.left
124 | case .top, .centerY, .lastBaseline, .firstBaseline:
125 | return value.top
126 | case .right:
127 | return -value.right
128 | case .bottom:
129 | return -value.bottom
130 | case .leading:
131 | return (ConstraintConfig.interfaceLayoutDirection == .leftToRight) ? value.left : value.right
132 | case .trailing:
133 | return (ConstraintConfig.interfaceLayoutDirection == .leftToRight) ? -value.right : -value.left
134 | case .width:
135 | return -(value.left + value.right)
136 | case .height:
137 | return -(value.top + value.bottom)
138 | case .notAnAttribute:
139 | return 0.0
140 | }
141 | #endif
142 | }
143 |
144 | return 0.0
145 | }
146 |
147 | }
148 |
--------------------------------------------------------------------------------
/ScanCodeDemo/SnapKit/Debugging.swift:
--------------------------------------------------------------------------------
1 | //
2 | // SnapKit
3 | //
4 | // Copyright (c) 2011-Present SnapKit Team - https://github.com/SnapKit
5 | //
6 | // Permission is hereby granted, free of charge, to any person obtaining a copy
7 | // of this software and associated documentation files (the "Software"), to deal
8 | // in the Software without restriction, including without limitation the rights
9 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 | // copies of the Software, and to permit persons to whom the Software is
11 | // furnished to do so, subject to the following conditions:
12 | //
13 | // The above copyright notice and this permission notice shall be included in
14 | // all copies or substantial portions of the Software.
15 | //
16 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22 | // THE SOFTWARE.
23 |
24 | #if os(iOS) || os(tvOS)
25 | import UIKit
26 | #else
27 | import AppKit
28 | #endif
29 |
30 | public extension LayoutConstraint {
31 |
32 | override public var description: String {
33 | var description = "<"
34 |
35 | description += descriptionForObject(self)
36 |
37 | if let firstItem = conditionalOptional(from: self.firstItem) {
38 | description += " \(descriptionForObject(firstItem))"
39 | }
40 |
41 | if self.firstAttribute != .notAnAttribute {
42 | description += ".\(descriptionForAttribute(self.firstAttribute))"
43 | }
44 |
45 | description += " \(descriptionForRelation(self.relation))"
46 |
47 | if let secondItem = self.secondItem {
48 | description += " \(descriptionForObject(secondItem))"
49 | }
50 |
51 | if self.secondAttribute != .notAnAttribute {
52 | description += ".\(descriptionForAttribute(self.secondAttribute))"
53 | }
54 |
55 | if self.multiplier != 1.0 {
56 | description += " * \(self.multiplier)"
57 | }
58 |
59 | if self.secondAttribute == .notAnAttribute {
60 | description += " \(self.constant)"
61 | } else {
62 | if self.constant > 0.0 {
63 | description += " + \(self.constant)"
64 | } else if self.constant < 0.0 {
65 | description += " - \(abs(self.constant))"
66 | }
67 | }
68 |
69 | if self.priority.rawValue != 1000.0 {
70 | description += " ^\(self.priority)"
71 | }
72 |
73 | description += ">"
74 |
75 | return description
76 | }
77 |
78 | }
79 |
80 | private func descriptionForRelation(_ relation: LayoutRelation) -> String {
81 | switch relation {
82 | case .equal: return "=="
83 | case .greaterThanOrEqual: return ">="
84 | case .lessThanOrEqual: return "<="
85 | }
86 | }
87 |
88 | private func descriptionForAttribute(_ attribute: LayoutAttribute) -> String {
89 | #if os(iOS) || os(tvOS)
90 | switch attribute {
91 | case .notAnAttribute: return "notAnAttribute"
92 | case .top: return "top"
93 | case .left: return "left"
94 | case .bottom: return "bottom"
95 | case .right: return "right"
96 | case .leading: return "leading"
97 | case .trailing: return "trailing"
98 | case .width: return "width"
99 | case .height: return "height"
100 | case .centerX: return "centerX"
101 | case .centerY: return "centerY"
102 | case .lastBaseline: return "lastBaseline"
103 | case .firstBaseline: return "firstBaseline"
104 | case .topMargin: return "topMargin"
105 | case .leftMargin: return "leftMargin"
106 | case .bottomMargin: return "bottomMargin"
107 | case .rightMargin: return "rightMargin"
108 | case .leadingMargin: return "leadingMargin"
109 | case .trailingMargin: return "trailingMargin"
110 | case .centerXWithinMargins: return "centerXWithinMargins"
111 | case .centerYWithinMargins: return "centerYWithinMargins"
112 | }
113 | #else
114 | switch attribute {
115 | case .notAnAttribute: return "notAnAttribute"
116 | case .top: return "top"
117 | case .left: return "left"
118 | case .bottom: return "bottom"
119 | case .right: return "right"
120 | case .leading: return "leading"
121 | case .trailing: return "trailing"
122 | case .width: return "width"
123 | case .height: return "height"
124 | case .centerX: return "centerX"
125 | case .centerY: return "centerY"
126 | case .lastBaseline: return "lastBaseline"
127 | case .firstBaseline: return "firstBaseline"
128 | }
129 | #endif
130 | }
131 |
132 | private func conditionalOptional(from object: Optional) -> Optional {
133 | return object
134 | }
135 |
136 | private func conditionalOptional(from object: T) -> Optional {
137 | return Optional.some(object)
138 | }
139 |
140 | private func descriptionForObject(_ object: AnyObject) -> String {
141 | let pointerDescription = String(format: "%p", UInt(bitPattern: ObjectIdentifier(object)))
142 | var desc = ""
143 |
144 | desc += type(of: object).description()
145 |
146 | if let object = object as? ConstraintView {
147 | desc += ":\(object.snp.label() ?? pointerDescription)"
148 | } else if let object = object as? LayoutConstraint {
149 | desc += ":\(object.label ?? pointerDescription)"
150 | } else {
151 | desc += ":\(pointerDescription)"
152 | }
153 |
154 | if let object = object as? LayoutConstraint, let file = object.constraint?.sourceLocation.0, let line = object.constraint?.sourceLocation.1 {
155 | desc += "@\((file as NSString).lastPathComponent)#\(line)"
156 | }
157 |
158 | desc += ""
159 | return desc
160 | }
161 |
--------------------------------------------------------------------------------
/ScanCodeDemo/SnapKit/ConstraintDSL.swift:
--------------------------------------------------------------------------------
1 | //
2 | // SnapKit
3 | //
4 | // Copyright (c) 2011-Present SnapKit Team - https://github.com/SnapKit
5 | //
6 | // Permission is hereby granted, free of charge, to any person obtaining a copy
7 | // of this software and associated documentation files (the "Software"), to deal
8 | // in the Software without restriction, including without limitation the rights
9 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 | // copies of the Software, and to permit persons to whom the Software is
11 | // furnished to do so, subject to the following conditions:
12 | //
13 | // The above copyright notice and this permission notice shall be included in
14 | // all copies or substantial portions of the Software.
15 | //
16 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22 | // THE SOFTWARE.
23 |
24 | #if os(iOS) || os(tvOS)
25 | import UIKit
26 | #else
27 | import AppKit
28 | #endif
29 |
30 |
31 | public protocol ConstraintDSL {
32 |
33 | var target: AnyObject? { get }
34 |
35 | func setLabel(_ value: String?)
36 | func label() -> String?
37 |
38 | }
39 | extension ConstraintDSL {
40 |
41 | public func setLabel(_ value: String?) {
42 | objc_setAssociatedObject(self.target as Any, &labelKey, value, .OBJC_ASSOCIATION_COPY_NONATOMIC)
43 | }
44 | public func label() -> String? {
45 | return objc_getAssociatedObject(self.target as Any, &labelKey) as? String
46 | }
47 |
48 | }
49 | private var labelKey: UInt8 = 0
50 |
51 |
52 | public protocol ConstraintBasicAttributesDSL : ConstraintDSL {
53 | }
54 | extension ConstraintBasicAttributesDSL {
55 |
56 | // MARK: Basics
57 |
58 | public var left: ConstraintItem {
59 | return ConstraintItem(target: self.target, attributes: ConstraintAttributes.left)
60 | }
61 |
62 | public var top: ConstraintItem {
63 | return ConstraintItem(target: self.target, attributes: ConstraintAttributes.top)
64 | }
65 |
66 | public var right: ConstraintItem {
67 | return ConstraintItem(target: self.target, attributes: ConstraintAttributes.right)
68 | }
69 |
70 | public var bottom: ConstraintItem {
71 | return ConstraintItem(target: self.target, attributes: ConstraintAttributes.bottom)
72 | }
73 |
74 | public var leading: ConstraintItem {
75 | return ConstraintItem(target: self.target, attributes: ConstraintAttributes.leading)
76 | }
77 |
78 | public var trailing: ConstraintItem {
79 | return ConstraintItem(target: self.target, attributes: ConstraintAttributes.trailing)
80 | }
81 |
82 | public var width: ConstraintItem {
83 | return ConstraintItem(target: self.target, attributes: ConstraintAttributes.width)
84 | }
85 |
86 | public var height: ConstraintItem {
87 | return ConstraintItem(target: self.target, attributes: ConstraintAttributes.height)
88 | }
89 |
90 | public var centerX: ConstraintItem {
91 | return ConstraintItem(target: self.target, attributes: ConstraintAttributes.centerX)
92 | }
93 |
94 | public var centerY: ConstraintItem {
95 | return ConstraintItem(target: self.target, attributes: ConstraintAttributes.centerY)
96 | }
97 |
98 | public var edges: ConstraintItem {
99 | return ConstraintItem(target: self.target, attributes: ConstraintAttributes.edges)
100 | }
101 |
102 | public var size: ConstraintItem {
103 | return ConstraintItem(target: self.target, attributes: ConstraintAttributes.size)
104 | }
105 |
106 | public var center: ConstraintItem {
107 | return ConstraintItem(target: self.target, attributes: ConstraintAttributes.center)
108 | }
109 |
110 | }
111 |
112 | public protocol ConstraintAttributesDSL : ConstraintBasicAttributesDSL {
113 | }
114 | extension ConstraintAttributesDSL {
115 |
116 | // MARK: Baselines
117 |
118 | @available(*, deprecated:3.0, message:"Use .lastBaseline instead")
119 | public var baseline: ConstraintItem {
120 | return ConstraintItem(target: self.target, attributes: ConstraintAttributes.lastBaseline)
121 | }
122 |
123 | @available(iOS 8.0, OSX 10.11, *)
124 | public var lastBaseline: ConstraintItem {
125 | return ConstraintItem(target: self.target, attributes: ConstraintAttributes.lastBaseline)
126 | }
127 |
128 | @available(iOS 8.0, OSX 10.11, *)
129 | public var firstBaseline: ConstraintItem {
130 | return ConstraintItem(target: self.target, attributes: ConstraintAttributes.firstBaseline)
131 | }
132 |
133 | // MARK: Margins
134 |
135 | @available(iOS 8.0, *)
136 | public var leftMargin: ConstraintItem {
137 | return ConstraintItem(target: self.target, attributes: ConstraintAttributes.leftMargin)
138 | }
139 |
140 | @available(iOS 8.0, *)
141 | public var topMargin: ConstraintItem {
142 | return ConstraintItem(target: self.target, attributes: ConstraintAttributes.topMargin)
143 | }
144 |
145 | @available(iOS 8.0, *)
146 | public var rightMargin: ConstraintItem {
147 | return ConstraintItem(target: self.target, attributes: ConstraintAttributes.rightMargin)
148 | }
149 |
150 | @available(iOS 8.0, *)
151 | public var bottomMargin: ConstraintItem {
152 | return ConstraintItem(target: self.target, attributes: ConstraintAttributes.bottomMargin)
153 | }
154 |
155 | @available(iOS 8.0, *)
156 | public var leadingMargin: ConstraintItem {
157 | return ConstraintItem(target: self.target, attributes: ConstraintAttributes.leadingMargin)
158 | }
159 |
160 | @available(iOS 8.0, *)
161 | public var trailingMargin: ConstraintItem {
162 | return ConstraintItem(target: self.target, attributes: ConstraintAttributes.trailingMargin)
163 | }
164 |
165 | @available(iOS 8.0, *)
166 | public var centerXWithinMargins: ConstraintItem {
167 | return ConstraintItem(target: self.target, attributes: ConstraintAttributes.centerXWithinMargins)
168 | }
169 |
170 | @available(iOS 8.0, *)
171 | public var centerYWithinMargins: ConstraintItem {
172 | return ConstraintItem(target: self.target, attributes: ConstraintAttributes.centerYWithinMargins)
173 | }
174 |
175 | @available(iOS 8.0, *)
176 | public var margins: ConstraintItem {
177 | return ConstraintItem(target: self.target, attributes: ConstraintAttributes.margins)
178 | }
179 |
180 | @available(iOS 8.0, *)
181 | public var centerWithinMargins: ConstraintItem {
182 | return ConstraintItem(target: self.target, attributes: ConstraintAttributes.centerWithinMargins)
183 | }
184 |
185 | }
186 |
--------------------------------------------------------------------------------
/ScanCodeDemo/SnapKit/ConstraintView+Extensions.swift:
--------------------------------------------------------------------------------
1 | //
2 | // SnapKit
3 | //
4 | // Copyright (c) 2011-Present SnapKit Team - https://github.com/SnapKit
5 | //
6 | // Permission is hereby granted, free of charge, to any person obtaining a copy
7 | // of this software and associated documentation files (the "Software"), to deal
8 | // in the Software without restriction, including without limitation the rights
9 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 | // copies of the Software, and to permit persons to whom the Software is
11 | // furnished to do so, subject to the following conditions:
12 | //
13 | // The above copyright notice and this permission notice shall be included in
14 | // all copies or substantial portions of the Software.
15 | //
16 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22 | // THE SOFTWARE.
23 |
24 | #if os(iOS) || os(tvOS)
25 | import UIKit
26 | #else
27 | import AppKit
28 | #endif
29 |
30 |
31 | public extension ConstraintView {
32 |
33 | @available(*, deprecated:3.0, message:"Use newer snp.* syntax.")
34 | public var snp_left: ConstraintItem { return self.snp.left }
35 |
36 | @available(*, deprecated:3.0, message:"Use newer snp.* syntax.")
37 | public var snp_top: ConstraintItem { return self.snp.top }
38 |
39 | @available(*, deprecated:3.0, message:"Use newer snp.* syntax.")
40 | public var snp_right: ConstraintItem { return self.snp.right }
41 |
42 | @available(*, deprecated:3.0, message:"Use newer snp.* syntax.")
43 | public var snp_bottom: ConstraintItem { return self.snp.bottom }
44 |
45 | @available(*, deprecated:3.0, message:"Use newer snp.* syntax.")
46 | public var snp_leading: ConstraintItem { return self.snp.leading }
47 |
48 | @available(*, deprecated:3.0, message:"Use newer snp.* syntax.")
49 | public var snp_trailing: ConstraintItem { return self.snp.trailing }
50 |
51 | @available(*, deprecated:3.0, message:"Use newer snp.* syntax.")
52 | public var snp_width: ConstraintItem { return self.snp.width }
53 |
54 | @available(*, deprecated:3.0, message:"Use newer snp.* syntax.")
55 | public var snp_height: ConstraintItem { return self.snp.height }
56 |
57 | @available(*, deprecated:3.0, message:"Use newer snp.* syntax.")
58 | public var snp_centerX: ConstraintItem { return self.snp.centerX }
59 |
60 | @available(*, deprecated:3.0, message:"Use newer snp.* syntax.")
61 | public var snp_centerY: ConstraintItem { return self.snp.centerY }
62 |
63 | @available(*, deprecated:3.0, message:"Use newer snp.* syntax.")
64 | public var snp_baseline: ConstraintItem { return self.snp.baseline }
65 |
66 | @available(*, deprecated:3.0, message:"Use newer snp.* syntax.")
67 | @available(iOS 8.0, OSX 10.11, *)
68 | public var snp_lastBaseline: ConstraintItem { return self.snp.lastBaseline }
69 |
70 | @available(iOS, deprecated:3.0, message:"Use newer snp.* syntax.")
71 | @available(iOS 8.0, OSX 10.11, *)
72 | public var snp_firstBaseline: ConstraintItem { return self.snp.firstBaseline }
73 |
74 | @available(iOS, deprecated:3.0, message:"Use newer snp.* syntax.")
75 | @available(iOS 8.0, *)
76 | public var snp_leftMargin: ConstraintItem { return self.snp.leftMargin }
77 |
78 | @available(iOS, deprecated:3.0, message:"Use newer snp.* syntax.")
79 | @available(iOS 8.0, *)
80 | public var snp_topMargin: ConstraintItem { return self.snp.topMargin }
81 |
82 | @available(iOS, deprecated:3.0, message:"Use newer snp.* syntax.")
83 | @available(iOS 8.0, *)
84 | public var snp_rightMargin: ConstraintItem { return self.snp.rightMargin }
85 |
86 | @available(iOS, deprecated:3.0, message:"Use newer snp.* syntax.")
87 | @available(iOS 8.0, *)
88 | public var snp_bottomMargin: ConstraintItem { return self.snp.bottomMargin }
89 |
90 | @available(iOS, deprecated:3.0, message:"Use newer snp.* syntax.")
91 | @available(iOS 8.0, *)
92 | public var snp_leadingMargin: ConstraintItem { return self.snp.leadingMargin }
93 |
94 | @available(iOS, deprecated:3.0, message:"Use newer snp.* syntax.")
95 | @available(iOS 8.0, *)
96 | public var snp_trailingMargin: ConstraintItem { return self.snp.trailingMargin }
97 |
98 | @available(iOS, deprecated:3.0, message:"Use newer snp.* syntax.")
99 | @available(iOS 8.0, *)
100 | public var snp_centerXWithinMargins: ConstraintItem { return self.snp.centerXWithinMargins }
101 |
102 | @available(iOS, deprecated:3.0, message:"Use newer snp.* syntax.")
103 | @available(iOS 8.0, *)
104 | public var snp_centerYWithinMargins: ConstraintItem { return self.snp.centerYWithinMargins }
105 |
106 | @available(*, deprecated:3.0, message:"Use newer snp.* syntax.")
107 | public var snp_edges: ConstraintItem { return self.snp.edges }
108 |
109 | @available(*, deprecated:3.0, message:"Use newer snp.* syntax.")
110 | public var snp_size: ConstraintItem { return self.snp.size }
111 |
112 | @available(*, deprecated:3.0, message:"Use newer snp.* syntax.")
113 | public var snp_center: ConstraintItem { return self.snp.center }
114 |
115 | @available(iOS, deprecated:3.0, message:"Use newer snp.* syntax.")
116 | @available(iOS 8.0, *)
117 | public var snp_margins: ConstraintItem { return self.snp.margins }
118 |
119 | @available(iOS, deprecated:3.0, message:"Use newer snp.* syntax.")
120 | @available(iOS 8.0, *)
121 | public var snp_centerWithinMargins: ConstraintItem { return self.snp.centerWithinMargins }
122 |
123 | @available(*, deprecated:3.0, message:"Use newer snp.* syntax.")
124 | public func snp_prepareConstraints(_ closure: (_ make: ConstraintMaker) -> Void) -> [Constraint] {
125 | return self.snp.prepareConstraints(closure)
126 | }
127 |
128 | @available(*, deprecated:3.0, message:"Use newer snp.* syntax.")
129 | public func snp_makeConstraints(_ closure: (_ make: ConstraintMaker) -> Void) {
130 | self.snp.makeConstraints(closure)
131 | }
132 |
133 | @available(*, deprecated:3.0, message:"Use newer snp.* syntax.")
134 | public func snp_remakeConstraints(_ closure: (_ make: ConstraintMaker) -> Void) {
135 | self.snp.remakeConstraints(closure)
136 | }
137 |
138 | @available(*, deprecated:3.0, message:"Use newer snp.* syntax.")
139 | public func snp_updateConstraints(_ closure: (_ make: ConstraintMaker) -> Void) {
140 | self.snp.updateConstraints(closure)
141 | }
142 |
143 | @available(*, deprecated:3.0, message:"Use newer snp.* syntax.")
144 | public func snp_removeConstraints() {
145 | self.snp.removeConstraints()
146 | }
147 |
148 | public var snp: ConstraintViewDSL {
149 | return ConstraintViewDSL(view: self)
150 | }
151 |
152 | }
153 |
--------------------------------------------------------------------------------
/ScanCodeDemo/base/UIImage+Additions.swift:
--------------------------------------------------------------------------------
1 | //
2 | // UIImage+Additions.swift
3 | // UIViewDemo
4 | //
5 | // Created by YTiOSer on 18/5.
6 | // Copyright © 2018 YTiOSer. All rights reserved.
7 | //
8 |
9 | import Foundation
10 | import UIKit
11 |
12 |
13 | extension UIImage {
14 |
15 | // MARK: - 裁剪给定得区域
16 | /// 裁剪给定得区域
17 | public func cropWithCropRect( _ crop: CGRect) -> UIImage?
18 | {
19 | let cropRect = CGRect(x: crop.origin.x * self.scale, y: crop.origin.y * self.scale, width: crop.size.width * self.scale, height: crop.size.height * self.scale)
20 |
21 | if cropRect.size.width <= 0 || cropRect.size.height <= 0 {
22 | return nil
23 | }
24 | var image:UIImage?
25 | autoreleasepool{
26 | let imageRef: CGImage? = self.cgImage!.cropping(to: cropRect)
27 | if let imageRef = imageRef {
28 | image = UIImage(cgImage: imageRef)
29 | }
30 | }
31 | return image
32 | }
33 |
34 | func imageByApplayingAlpha(_ alpha: CGFloat) -> UIImage {
35 | UIGraphicsBeginImageContext(size)
36 | let context = UIGraphicsGetCurrentContext()
37 | let area = CGRect(x: 0, y: 0, width: size.width, height: size.height)
38 | context?.scaleBy(x: 1, y: -1)
39 | context?.translateBy(x: 0, y: -area.height)
40 | context?.setBlendMode(.multiply)
41 | context?.setAlpha(alpha)
42 | context?.draw(self.cgImage!, in: area)
43 | let newImage = UIGraphicsGetImageFromCurrentImageContext()
44 | UIGraphicsEndImageContext()
45 | return newImage ?? self
46 | }
47 |
48 | // MARK: - 旋转
49 | public func imageByRotate(_ radians: CGFloat, _ fitSize: Bool) -> UIImage? {
50 | guard let cgImage = cgImage else { return nil }
51 | let width: Int = cgImage.width
52 | let height: Int = cgImage.height
53 | let newRect: CGRect = CGRect(x: 0.0, y: 0.0, width: CGFloat(width), height: CGFloat(height)).applying(fitSize ? CGAffineTransform(rotationAngle: radians) : CGAffineTransform.identity)
54 | var resultImage: UIImage?
55 | autoreleasepool {
56 | let colorSpace: CGColorSpace = CGColorSpaceCreateDeviceGray()
57 | if let context = CGContext(data: nil, width: Int(newRect.size.width), height: Int(newRect.size.height),bitsPerComponent: 8,bytesPerRow: Int(newRect.size.width * 4), space: colorSpace, bitmapInfo: CGImageAlphaInfo.none.rawValue) {
58 | context.setShouldAntialias(true)
59 | context.setAllowsAntialiasing(true)
60 | context.interpolationQuality = CGInterpolationQuality.high;
61 | context.translateBy(x: +(newRect.size.width * 0.5), y: +(newRect.size.height * 0.5))
62 | context.rotate(by: radians)
63 | context.draw(self.cgImage!, in: CGRect(x: -(CGFloat(width) * 0.5), y: -(CGFloat(height) * 0.5), width: CGFloat(width), height: CGFloat(height)))
64 | if let imgRef: CGImage = context.makeImage() {
65 | resultImage = UIImage(cgImage: imgRef)
66 | }
67 | }
68 | }
69 | return resultImage;
70 | }
71 |
72 | //MARK: - 按比例裁剪图片
73 | func scaleToSize(_ size: CGSize) -> UIImage {
74 | UIGraphicsBeginImageContext(size)
75 | self.draw(in: CGRect(x: 0, y: 0, width: size.width, height: size.height))
76 | let scaledImage = UIGraphicsGetImageFromCurrentImageContext()
77 | UIGraphicsEndImageContext()
78 | return scaledImage!
79 | }
80 |
81 | /// 按比例减少尺寸
82 | ///
83 | /// - Parameter sz: 原始图像尺寸.
84 | /// - Parameter limit:目标尺寸.
85 | /// - Returns: 函数按比例返回缩小后的尺寸
86 | /// - Complexity: O(*n*)
87 |
88 | func reduceSize(_ sz: CGSize, _ limit: CGFloat) -> CGSize {
89 | let maxPixel = max(sz.width, sz.height)
90 | guard maxPixel > limit else {
91 | return sz
92 | }
93 | var resSize: CGSize!
94 | let ratio = sz.height / sz.width;
95 |
96 | if (sz.width > sz.height) {
97 | resSize = CGSize(width:limit, height:limit*ratio);
98 | } else {
99 | resSize = CGSize(width:limit/ratio, height:limit);
100 | }
101 |
102 | return resSize;
103 | }
104 |
105 | // MARK: - 图片缩放
106 | /// 按比例减少给定图像的尺寸
107 | ///
108 | /// eg:
109 | /// 压缩方式一:最大边不超过某个值等比例压缩
110 | /// let px_1000_img = oldImg?.scaleImage(1000.0)
111 | /// let px_1000_data = UIImageJPEGRepresentation(px_1000_img!, 0.7)
112 | /// tv.text.append("最大边不超过1000PX的大小 \(M(Double(px_1000_data!.count))) M \n")
113 | /// tv.text.append("最大边不超过1000PX宽度 \(String(describing: px_1000_img?.size.width))\n")
114 | /// tv.text.append("最大边不超过1000PX高度 \(String(describing: px_1000_img?.size.height))\n\n")
115 | /// tv.text.append("-------------------------------\n")
116 | ///
117 | /// - Parameter maxSideLength: 缩小后的尺寸.
118 | ///
119 | /// - Returns: 函数按比例返回缩小后的图像
120 | func scaleImage(_ maxSideLength: CGFloat) -> UIImage {
121 | guard size.width > maxSideLength || size.height > maxSideLength else {
122 | return self
123 | }
124 | let imgSize = reduceSize(size, maxSideLength)
125 | var img: UIImage!
126 | // 1 代表1X
127 | UIGraphicsBeginImageContextWithOptions(imgSize, true, 1.0)
128 | self.draw(in: CGRect(x: 0, y: 0, width: imgSize.width, height: imgSize.height), blendMode: .normal, alpha: 1.0)
129 | img = UIGraphicsGetImageFromCurrentImageContext();
130 | UIGraphicsEndImageContext();
131 |
132 | return img
133 | }
134 | // MARK: - 图片压缩
135 | /// 图片压缩
136 | ///
137 | /// eg:
138 | /// oldImg?.compressImage(1024*1024*1, 1000.0, {(data) in
139 | /// let img = UIImage(data: data)
140 | /// tv.text.append("图片最大值不超过最大边1M 以及 最大边不超过1000PX的大小 \(self.M(Double((data.count)))) M\n")
141 | /// tv.text.append("图片最大值不超过最大边1M 以及 最大边不超过1000PX的宽度 \(img!.size.width)\n")
142 | /// tv.text.append("图片最大值不超过最大边1M 以及 最大边不超过1000PX的高度 \(img!.size.height)\n\n")
143 | /// tv.text.append("-------------------------------\n")
144 | /// })
145 | ///
146 | /// - Parameter limitSize:限制图像的大小.
147 | /// - Parameter maxSideLength: 缩小后的尺寸.
148 | /// - Parameter completion: 闭包回调.
149 | /// - Returns: 函数按比例返回压缩后的图像
150 | func compressImage( _ limitSize: Int, _ maxSideLength: CGFloat, _ completion: @escaping (_ dataImg: Data)->Void ) {
151 | guard limitSize>0 || maxSideLength>0 else {
152 | return
153 | }
154 | //weak var weakSelf = self
155 | let compressQueue = DispatchQueue(label: "image_compress_queue")
156 | compressQueue.async {
157 | var quality = 0.7
158 | //let img = weakSelf?.scaleImage(maxSideLength)
159 | let img = self.scaleImage(maxSideLength)
160 | var imageData = UIImageJPEGRepresentation(img, CGFloat(quality) )
161 | guard imageData != nil else { return }
162 | if (imageData?.count)! <= limitSize {
163 | DispatchQueue.main.async(execute: {//在主线程里刷新界面
164 | completion(imageData!)
165 | })
166 | return
167 | }
168 |
169 | repeat {
170 | autoreleasepool {
171 | imageData = UIImageJPEGRepresentation(img, CGFloat(quality))
172 | quality = quality-0.05
173 | }
174 | } while ((imageData?.count)! > limitSize);
175 | DispatchQueue.main.async(execute: {//在主线程里刷新界面
176 | completion(imageData!)
177 | })
178 | }
179 | }
180 | }
181 |
--------------------------------------------------------------------------------
/ScanCodeDemo/SnapKit/ConstraintAttributes.swift:
--------------------------------------------------------------------------------
1 | //
2 | // SnapKit
3 | //
4 | // Copyright (c) 2011-Present SnapKit Team - https://github.com/SnapKit
5 | //
6 | // Permission is hereby granted, free of charge, to any person obtaining a copy
7 | // of this software and associated documentation files (the "Software"), to deal
8 | // in the Software without restriction, including without limitation the rights
9 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 | // copies of the Software, and to permit persons to whom the Software is
11 | // furnished to do so, subject to the following conditions:
12 | //
13 | // The above copyright notice and this permission notice shall be included in
14 | // all copies or substantial portions of the Software.
15 | //
16 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22 | // THE SOFTWARE.
23 |
24 | #if os(iOS) || os(tvOS)
25 | import UIKit
26 | #else
27 | import AppKit
28 | #endif
29 |
30 |
31 | internal struct ConstraintAttributes : OptionSet {
32 |
33 | internal init(rawValue: UInt) {
34 | self.rawValue = rawValue
35 | }
36 | internal init(_ rawValue: UInt) {
37 | self.init(rawValue: rawValue)
38 | }
39 | internal init(nilLiteral: ()) {
40 | self.rawValue = 0
41 | }
42 |
43 | internal private(set) var rawValue: UInt
44 | internal static var allZeros: ConstraintAttributes { return self.init(0) }
45 | internal static func convertFromNilLiteral() -> ConstraintAttributes { return self.init(0) }
46 | internal var boolValue: Bool { return self.rawValue != 0 }
47 |
48 | internal func toRaw() -> UInt { return self.rawValue }
49 | internal static func fromRaw(_ raw: UInt) -> ConstraintAttributes? { return self.init(raw) }
50 | internal static func fromMask(_ raw: UInt) -> ConstraintAttributes { return self.init(raw) }
51 |
52 | // normal
53 |
54 | internal static var none: ConstraintAttributes { return self.init(0) }
55 | internal static var left: ConstraintAttributes { return self.init(1) }
56 | internal static var top: ConstraintAttributes { return self.init(2) }
57 | internal static var right: ConstraintAttributes { return self.init(4) }
58 | internal static var bottom: ConstraintAttributes { return self.init(8) }
59 | internal static var leading: ConstraintAttributes { return self.init(16) }
60 | internal static var trailing: ConstraintAttributes { return self.init(32) }
61 | internal static var width: ConstraintAttributes { return self.init(64) }
62 | internal static var height: ConstraintAttributes { return self.init(128) }
63 | internal static var centerX: ConstraintAttributes { return self.init(256) }
64 | internal static var centerY: ConstraintAttributes { return self.init(512) }
65 | internal static var lastBaseline: ConstraintAttributes { return self.init(1024) }
66 |
67 | @available(iOS 8.0, OSX 10.11, *)
68 | internal static var firstBaseline: ConstraintAttributes { return self.init(2048) }
69 |
70 | @available(iOS 8.0, *)
71 | internal static var leftMargin: ConstraintAttributes { return self.init(4096) }
72 |
73 | @available(iOS 8.0, *)
74 | internal static var rightMargin: ConstraintAttributes { return self.init(8192) }
75 |
76 | @available(iOS 8.0, *)
77 | internal static var topMargin: ConstraintAttributes { return self.init(16384) }
78 |
79 | @available(iOS 8.0, *)
80 | internal static var bottomMargin: ConstraintAttributes { return self.init(32768) }
81 |
82 | @available(iOS 8.0, *)
83 | internal static var leadingMargin: ConstraintAttributes { return self.init(65536) }
84 |
85 | @available(iOS 8.0, *)
86 | internal static var trailingMargin: ConstraintAttributes { return self.init(131072) }
87 |
88 | @available(iOS 8.0, *)
89 | internal static var centerXWithinMargins: ConstraintAttributes { return self.init(262144) }
90 |
91 | @available(iOS 8.0, *)
92 | internal static var centerYWithinMargins: ConstraintAttributes { return self.init(524288) }
93 |
94 | // aggregates
95 |
96 | internal static var edges: ConstraintAttributes { return self.init(15) }
97 | internal static var size: ConstraintAttributes { return self.init(192) }
98 | internal static var center: ConstraintAttributes { return self.init(768) }
99 |
100 | @available(iOS 8.0, *)
101 | internal static var margins: ConstraintAttributes { return self.init(61440) }
102 |
103 | @available(iOS 8.0, *)
104 | internal static var centerWithinMargins: ConstraintAttributes { return self.init(786432) }
105 |
106 | internal var layoutAttributes:[LayoutAttribute] {
107 | var attrs = [LayoutAttribute]()
108 | if (self.contains(ConstraintAttributes.left)) {
109 | attrs.append(.left)
110 | }
111 | if (self.contains(ConstraintAttributes.top)) {
112 | attrs.append(.top)
113 | }
114 | if (self.contains(ConstraintAttributes.right)) {
115 | attrs.append(.right)
116 | }
117 | if (self.contains(ConstraintAttributes.bottom)) {
118 | attrs.append(.bottom)
119 | }
120 | if (self.contains(ConstraintAttributes.leading)) {
121 | attrs.append(.leading)
122 | }
123 | if (self.contains(ConstraintAttributes.trailing)) {
124 | attrs.append(.trailing)
125 | }
126 | if (self.contains(ConstraintAttributes.width)) {
127 | attrs.append(.width)
128 | }
129 | if (self.contains(ConstraintAttributes.height)) {
130 | attrs.append(.height)
131 | }
132 | if (self.contains(ConstraintAttributes.centerX)) {
133 | attrs.append(.centerX)
134 | }
135 | if (self.contains(ConstraintAttributes.centerY)) {
136 | attrs.append(.centerY)
137 | }
138 | if (self.contains(ConstraintAttributes.lastBaseline)) {
139 | attrs.append(.lastBaseline)
140 | }
141 |
142 | #if os(iOS) || os(tvOS)
143 | if (self.contains(ConstraintAttributes.firstBaseline)) {
144 | attrs.append(.firstBaseline)
145 | }
146 | if (self.contains(ConstraintAttributes.leftMargin)) {
147 | attrs.append(.leftMargin)
148 | }
149 | if (self.contains(ConstraintAttributes.rightMargin)) {
150 | attrs.append(.rightMargin)
151 | }
152 | if (self.contains(ConstraintAttributes.topMargin)) {
153 | attrs.append(.topMargin)
154 | }
155 | if (self.contains(ConstraintAttributes.bottomMargin)) {
156 | attrs.append(.bottomMargin)
157 | }
158 | if (self.contains(ConstraintAttributes.leadingMargin)) {
159 | attrs.append(.leadingMargin)
160 | }
161 | if (self.contains(ConstraintAttributes.trailingMargin)) {
162 | attrs.append(.trailingMargin)
163 | }
164 | if (self.contains(ConstraintAttributes.centerXWithinMargins)) {
165 | attrs.append(.centerXWithinMargins)
166 | }
167 | if (self.contains(ConstraintAttributes.centerYWithinMargins)) {
168 | attrs.append(.centerYWithinMargins)
169 | }
170 | #endif
171 |
172 | return attrs
173 | }
174 | }
175 |
176 | internal func + (left: ConstraintAttributes, right: ConstraintAttributes) -> ConstraintAttributes {
177 | return left.union(right)
178 | }
179 |
180 | internal func +=(left: inout ConstraintAttributes, right: ConstraintAttributes) {
181 | left.formUnion(right)
182 | }
183 |
184 | internal func -=(left: inout ConstraintAttributes, right: ConstraintAttributes) {
185 | left.subtract(right)
186 | }
187 |
188 | internal func ==(left: ConstraintAttributes, right: ConstraintAttributes) -> Bool {
189 | return left.rawValue == right.rawValue
190 | }
191 |
--------------------------------------------------------------------------------
/ScanCodeDemo/SnapKit/ConstraintMaker.swift:
--------------------------------------------------------------------------------
1 | //
2 | // SnapKit
3 | //
4 | // Copyright (c) 2011-Present SnapKit Team - https://github.com/SnapKit
5 | //
6 | // Permission is hereby granted, free of charge, to any person obtaining a copy
7 | // of this software and associated documentation files (the "Software"), to deal
8 | // in the Software without restriction, including without limitation the rights
9 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 | // copies of the Software, and to permit persons to whom the Software is
11 | // furnished to do so, subject to the following conditions:
12 | //
13 | // The above copyright notice and this permission notice shall be included in
14 | // all copies or substantial portions of the Software.
15 | //
16 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22 | // THE SOFTWARE.
23 |
24 | #if os(iOS) || os(tvOS)
25 | import UIKit
26 | #else
27 | import AppKit
28 | #endif
29 |
30 | public class ConstraintMaker {
31 |
32 | public var left: ConstraintMakerExtendable {
33 | return self.makeExtendableWithAttributes(.left)
34 | }
35 |
36 | public var top: ConstraintMakerExtendable {
37 | return self.makeExtendableWithAttributes(.top)
38 | }
39 |
40 | public var bottom: ConstraintMakerExtendable {
41 | return self.makeExtendableWithAttributes(.bottom)
42 | }
43 |
44 | public var right: ConstraintMakerExtendable {
45 | return self.makeExtendableWithAttributes(.right)
46 | }
47 |
48 | public var leading: ConstraintMakerExtendable {
49 | return self.makeExtendableWithAttributes(.leading)
50 | }
51 |
52 | public var trailing: ConstraintMakerExtendable {
53 | return self.makeExtendableWithAttributes(.trailing)
54 | }
55 |
56 | public var width: ConstraintMakerExtendable {
57 | return self.makeExtendableWithAttributes(.width)
58 | }
59 |
60 | public var height: ConstraintMakerExtendable {
61 | return self.makeExtendableWithAttributes(.height)
62 | }
63 |
64 | public var centerX: ConstraintMakerExtendable {
65 | return self.makeExtendableWithAttributes(.centerX)
66 | }
67 |
68 | public var centerY: ConstraintMakerExtendable {
69 | return self.makeExtendableWithAttributes(.centerY)
70 | }
71 |
72 | @available(*, deprecated:3.0, message:"Use lastBaseline instead")
73 | public var baseline: ConstraintMakerExtendable {
74 | return self.makeExtendableWithAttributes(.lastBaseline)
75 | }
76 |
77 | public var lastBaseline: ConstraintMakerExtendable {
78 | return self.makeExtendableWithAttributes(.lastBaseline)
79 | }
80 |
81 | @available(iOS 8.0, OSX 10.11, *)
82 | public var firstBaseline: ConstraintMakerExtendable {
83 | return self.makeExtendableWithAttributes(.firstBaseline)
84 | }
85 |
86 | @available(iOS 8.0, *)
87 | public var leftMargin: ConstraintMakerExtendable {
88 | return self.makeExtendableWithAttributes(.leftMargin)
89 | }
90 |
91 | @available(iOS 8.0, *)
92 | public var rightMargin: ConstraintMakerExtendable {
93 | return self.makeExtendableWithAttributes(.rightMargin)
94 | }
95 |
96 | @available(iOS 8.0, *)
97 | public var topMargin: ConstraintMakerExtendable {
98 | return self.makeExtendableWithAttributes(.topMargin)
99 | }
100 |
101 | @available(iOS 8.0, *)
102 | public var bottomMargin: ConstraintMakerExtendable {
103 | return self.makeExtendableWithAttributes(.bottomMargin)
104 | }
105 |
106 | @available(iOS 8.0, *)
107 | public var leadingMargin: ConstraintMakerExtendable {
108 | return self.makeExtendableWithAttributes(.leadingMargin)
109 | }
110 |
111 | @available(iOS 8.0, *)
112 | public var trailingMargin: ConstraintMakerExtendable {
113 | return self.makeExtendableWithAttributes(.trailingMargin)
114 | }
115 |
116 | @available(iOS 8.0, *)
117 | public var centerXWithinMargins: ConstraintMakerExtendable {
118 | return self.makeExtendableWithAttributes(.centerXWithinMargins)
119 | }
120 |
121 | @available(iOS 8.0, *)
122 | public var centerYWithinMargins: ConstraintMakerExtendable {
123 | return self.makeExtendableWithAttributes(.centerYWithinMargins)
124 | }
125 |
126 | public var edges: ConstraintMakerExtendable {
127 | return self.makeExtendableWithAttributes(.edges)
128 | }
129 | public var size: ConstraintMakerExtendable {
130 | return self.makeExtendableWithAttributes(.size)
131 | }
132 | public var center: ConstraintMakerExtendable {
133 | return self.makeExtendableWithAttributes(.center)
134 | }
135 |
136 | @available(iOS 8.0, *)
137 | public var margins: ConstraintMakerExtendable {
138 | return self.makeExtendableWithAttributes(.margins)
139 | }
140 |
141 | @available(iOS 8.0, *)
142 | public var centerWithinMargins: ConstraintMakerExtendable {
143 | return self.makeExtendableWithAttributes(.centerWithinMargins)
144 | }
145 |
146 | private let item: LayoutConstraintItem
147 | private var descriptions = [ConstraintDescription]()
148 |
149 | internal init(item: LayoutConstraintItem) {
150 | self.item = item
151 | self.item.prepare()
152 | }
153 |
154 | internal func makeExtendableWithAttributes(_ attributes: ConstraintAttributes) -> ConstraintMakerExtendable {
155 | let description = ConstraintDescription(item: self.item, attributes: attributes)
156 | self.descriptions.append(description)
157 | return ConstraintMakerExtendable(description)
158 | }
159 |
160 | internal static func prepareConstraints(item: LayoutConstraintItem, closure: (_ make: ConstraintMaker) -> Void) -> [Constraint] {
161 | let maker = ConstraintMaker(item: item)
162 | closure(maker)
163 | var constraints: [Constraint] = []
164 | for description in maker.descriptions {
165 | guard let constraint = description.constraint else {
166 | continue
167 | }
168 | constraints.append(constraint)
169 | }
170 | return constraints
171 | }
172 |
173 | internal static func makeConstraints(item: LayoutConstraintItem, closure: (_ make: ConstraintMaker) -> Void) {
174 | let maker = ConstraintMaker(item: item)
175 | closure(maker)
176 | var constraints: [Constraint] = []
177 | for description in maker.descriptions {
178 | guard let constraint = description.constraint else {
179 | continue
180 | }
181 | constraints.append(constraint)
182 | }
183 | for constraint in constraints {
184 | constraint.activateIfNeeded(updatingExisting: false)
185 | }
186 | }
187 |
188 | internal static func remakeConstraints(item: LayoutConstraintItem, closure: (_ make: ConstraintMaker) -> Void) {
189 | self.removeConstraints(item: item)
190 | self.makeConstraints(item: item, closure: closure)
191 | }
192 |
193 | internal static func updateConstraints(item: LayoutConstraintItem, closure: (_ make: ConstraintMaker) -> Void) {
194 | guard item.constraints.count > 0 else {
195 | self.makeConstraints(item: item, closure: closure)
196 | return
197 | }
198 |
199 | let maker = ConstraintMaker(item: item)
200 | closure(maker)
201 | var constraints: [Constraint] = []
202 | for description in maker.descriptions {
203 | guard let constraint = description.constraint else {
204 | continue
205 | }
206 | constraints.append(constraint)
207 | }
208 | for constraint in constraints {
209 | constraint.activateIfNeeded(updatingExisting: true)
210 | }
211 | }
212 |
213 | internal static func removeConstraints(item: LayoutConstraintItem) {
214 | let constraints = item.constraints
215 | for constraint in constraints {
216 | constraint.deactivateIfNeeded()
217 | }
218 | }
219 |
220 | }
221 |
--------------------------------------------------------------------------------
/ScanCodeDemo/SnapKit/Constraint.swift:
--------------------------------------------------------------------------------
1 | //
2 | // SnapKit
3 | //
4 | // Copyright (c) 2011-Present SnapKit Team - https://github.com/SnapKit
5 | //
6 | // Permission is hereby granted, free of charge, to any person obtaining a copy
7 | // of this software and associated documentation files (the "Software"), to deal
8 | // in the Software without restriction, including without limitation the rights
9 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 | // copies of the Software, and to permit persons to whom the Software is
11 | // furnished to do so, subject to the following conditions:
12 | //
13 | // The above copyright notice and this permission notice shall be included in
14 | // all copies or substantial portions of the Software.
15 | //
16 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22 | // THE SOFTWARE.
23 |
24 | #if os(iOS) || os(tvOS)
25 | import UIKit
26 | #else
27 | import AppKit
28 | #endif
29 |
30 | public final class Constraint {
31 |
32 | internal let sourceLocation: (String, UInt)
33 | internal let label: String?
34 |
35 | private let from: ConstraintItem
36 | private let to: ConstraintItem
37 | private let relation: ConstraintRelation
38 | private let multiplier: ConstraintMultiplierTarget
39 | private var constant: ConstraintConstantTarget {
40 | didSet {
41 | self.updateConstantAndPriorityIfNeeded()
42 | }
43 | }
44 | private var priority: ConstraintPriorityTarget {
45 | didSet {
46 | self.updateConstantAndPriorityIfNeeded()
47 | }
48 | }
49 | public var layoutConstraints: [LayoutConstraint]
50 |
51 | public var isActive: Bool {
52 | for layoutConstraint in self.layoutConstraints {
53 | if layoutConstraint.isActive {
54 | return true
55 | }
56 | }
57 | return false
58 | }
59 |
60 | // MARK: Initialization
61 |
62 | internal init(from: ConstraintItem,
63 | to: ConstraintItem,
64 | relation: ConstraintRelation,
65 | sourceLocation: (String, UInt),
66 | label: String?,
67 | multiplier: ConstraintMultiplierTarget,
68 | constant: ConstraintConstantTarget,
69 | priority: ConstraintPriorityTarget) {
70 | self.from = from
71 | self.to = to
72 | self.relation = relation
73 | self.sourceLocation = sourceLocation
74 | self.label = label
75 | self.multiplier = multiplier
76 | self.constant = constant
77 | self.priority = priority
78 | self.layoutConstraints = []
79 |
80 | // get attributes
81 | let layoutFromAttributes = self.from.attributes.layoutAttributes
82 | let layoutToAttributes = self.to.attributes.layoutAttributes
83 |
84 | // get layout from
85 | let layoutFrom = self.from.layoutConstraintItem!
86 |
87 | // get relation
88 | let layoutRelation = self.relation.layoutRelation
89 |
90 | for layoutFromAttribute in layoutFromAttributes {
91 | // get layout to attribute
92 | let layoutToAttribute: LayoutAttribute
93 | #if os(iOS) || os(tvOS)
94 | if layoutToAttributes.count > 0 {
95 | if self.from.attributes == .edges && self.to.attributes == .margins {
96 | switch layoutFromAttribute {
97 | case .left:
98 | layoutToAttribute = .leftMargin
99 | case .right:
100 | layoutToAttribute = .rightMargin
101 | case .top:
102 | layoutToAttribute = .topMargin
103 | case .bottom:
104 | layoutToAttribute = .bottomMargin
105 | default:
106 | fatalError()
107 | }
108 | } else if self.from.attributes == .margins && self.to.attributes == .edges {
109 | switch layoutFromAttribute {
110 | case .leftMargin:
111 | layoutToAttribute = .left
112 | case .rightMargin:
113 | layoutToAttribute = .right
114 | case .topMargin:
115 | layoutToAttribute = .top
116 | case .bottomMargin:
117 | layoutToAttribute = .bottom
118 | default:
119 | fatalError()
120 | }
121 | } else if self.from.attributes == self.to.attributes {
122 | layoutToAttribute = layoutFromAttribute
123 | } else {
124 | layoutToAttribute = layoutToAttributes[0]
125 | }
126 | } else {
127 | if self.to.target == nil && (layoutFromAttribute == .centerX || layoutFromAttribute == .centerY) {
128 | layoutToAttribute = layoutFromAttribute == .centerX ? .left : .top
129 | } else {
130 | layoutToAttribute = layoutFromAttribute
131 | }
132 | }
133 | #else
134 | if self.from.attributes == self.to.attributes {
135 | layoutToAttribute = layoutFromAttribute
136 | } else if layoutToAttributes.count > 0 {
137 | layoutToAttribute = layoutToAttributes[0]
138 | } else {
139 | layoutToAttribute = layoutFromAttribute
140 | }
141 | #endif
142 |
143 | // get layout constant
144 | let layoutConstant: CGFloat = self.constant.constraintConstantTargetValueFor(layoutAttribute: layoutToAttribute)
145 |
146 | // get layout to
147 | var layoutTo: AnyObject? = self.to.target
148 |
149 | // use superview if possible
150 | if layoutTo == nil && layoutToAttribute != .width && layoutToAttribute != .height {
151 | layoutTo = layoutFrom.superview
152 | }
153 |
154 | // create layout constraint
155 | let layoutConstraint = LayoutConstraint(
156 | item: layoutFrom,
157 | attribute: layoutFromAttribute,
158 | relatedBy: layoutRelation,
159 | toItem: layoutTo,
160 | attribute: layoutToAttribute,
161 | multiplier: self.multiplier.constraintMultiplierTargetValue,
162 | constant: layoutConstant
163 | )
164 |
165 | // set label
166 | layoutConstraint.label = self.label
167 |
168 | // set priority
169 | layoutConstraint.priority = LayoutPriority(rawValue: self.priority.constraintPriorityTargetValue)
170 |
171 | // set constraint
172 | layoutConstraint.constraint = self
173 |
174 | // append
175 | self.layoutConstraints.append(layoutConstraint)
176 | }
177 | }
178 |
179 | // MARK: Public
180 |
181 | @available(*, deprecated:3.0, message:"Use activate().")
182 | public func install() {
183 | self.activate()
184 | }
185 |
186 | @available(*, deprecated:3.0, message:"Use deactivate().")
187 | public func uninstall() {
188 | self.deactivate()
189 | }
190 |
191 | public func activate() {
192 | self.activateIfNeeded()
193 | }
194 |
195 | public func deactivate() {
196 | self.deactivateIfNeeded()
197 | }
198 |
199 | @discardableResult
200 | public func update(offset: ConstraintOffsetTarget) -> Constraint {
201 | self.constant = offset.constraintOffsetTargetValue
202 | return self
203 | }
204 |
205 | @discardableResult
206 | public func update(inset: ConstraintInsetTarget) -> Constraint {
207 | self.constant = inset.constraintInsetTargetValue
208 | return self
209 | }
210 |
211 | @discardableResult
212 | public func update(priority: ConstraintPriorityTarget) -> Constraint {
213 | self.priority = priority.constraintPriorityTargetValue
214 | return self
215 | }
216 |
217 | @discardableResult
218 | public func update(priority: ConstraintPriority) -> Constraint {
219 | self.priority = priority.value
220 | return self
221 | }
222 |
223 | @available(*, deprecated:3.0, message:"Use update(offset: ConstraintOffsetTarget) instead.")
224 | public func updateOffset(amount: ConstraintOffsetTarget) -> Void { self.update(offset: amount) }
225 |
226 | @available(*, deprecated:3.0, message:"Use update(inset: ConstraintInsetTarget) instead.")
227 | public func updateInsets(amount: ConstraintInsetTarget) -> Void { self.update(inset: amount) }
228 |
229 | @available(*, deprecated:3.0, message:"Use update(priority: ConstraintPriorityTarget) instead.")
230 | public func updatePriority(amount: ConstraintPriorityTarget) -> Void { self.update(priority: amount) }
231 |
232 | @available(*, obsoleted:3.0, message:"Use update(priority: ConstraintPriorityTarget) instead.")
233 | public func updatePriorityRequired() -> Void {}
234 |
235 | @available(*, obsoleted:3.0, message:"Use update(priority: ConstraintPriorityTarget) instead.")
236 | public func updatePriorityHigh() -> Void { fatalError("Must be implemented by Concrete subclass.") }
237 |
238 | @available(*, obsoleted:3.0, message:"Use update(priority: ConstraintPriorityTarget) instead.")
239 | public func updatePriorityMedium() -> Void { fatalError("Must be implemented by Concrete subclass.") }
240 |
241 | @available(*, obsoleted:3.0, message:"Use update(priority: ConstraintPriorityTarget) instead.")
242 | public func updatePriorityLow() -> Void { fatalError("Must be implemented by Concrete subclass.") }
243 |
244 | // MARK: Internal
245 |
246 | internal func updateConstantAndPriorityIfNeeded() {
247 | for layoutConstraint in self.layoutConstraints {
248 | let attribute = (layoutConstraint.secondAttribute == .notAnAttribute) ? layoutConstraint.firstAttribute : layoutConstraint.secondAttribute
249 | layoutConstraint.constant = self.constant.constraintConstantTargetValueFor(layoutAttribute: attribute)
250 |
251 | let requiredPriority = ConstraintPriority.required.value
252 | if (layoutConstraint.priority.rawValue < requiredPriority), (self.priority.constraintPriorityTargetValue != requiredPriority) {
253 | layoutConstraint.priority = LayoutPriority(rawValue: self.priority.constraintPriorityTargetValue)
254 | }
255 | }
256 | }
257 |
258 | internal func activateIfNeeded(updatingExisting: Bool = false) {
259 | guard let item = self.from.layoutConstraintItem else {
260 | print("WARNING: SnapKit failed to get from item from constraint. Activate will be a no-op.")
261 | return
262 | }
263 | let layoutConstraints = self.layoutConstraints
264 |
265 | if updatingExisting {
266 | var existingLayoutConstraints: [LayoutConstraint] = []
267 | for constraint in item.constraints {
268 | existingLayoutConstraints += constraint.layoutConstraints
269 | }
270 |
271 | for layoutConstraint in layoutConstraints {
272 | let existingLayoutConstraint = existingLayoutConstraints.first { $0 == layoutConstraint }
273 | guard let updateLayoutConstraint = existingLayoutConstraint else {
274 | fatalError("Updated constraint could not find existing matching constraint to update: \(layoutConstraint)")
275 | }
276 |
277 | let updateLayoutAttribute = (updateLayoutConstraint.secondAttribute == .notAnAttribute) ? updateLayoutConstraint.firstAttribute : updateLayoutConstraint.secondAttribute
278 | updateLayoutConstraint.constant = self.constant.constraintConstantTargetValueFor(layoutAttribute: updateLayoutAttribute)
279 | }
280 | } else {
281 | NSLayoutConstraint.activate(layoutConstraints)
282 | item.add(constraints: [self])
283 | }
284 | }
285 |
286 | internal func deactivateIfNeeded() {
287 | guard let item = self.from.layoutConstraintItem else {
288 | print("WARNING: SnapKit failed to get from item from constraint. Deactivate will be a no-op.")
289 | return
290 | }
291 | let layoutConstraints = self.layoutConstraints
292 | NSLayoutConstraint.deactivate(layoutConstraints)
293 | item.remove(constraints: [self])
294 | }
295 | }
296 |
--------------------------------------------------------------------------------
/ScanCodeDemo/ScanCode/controller/YTScanCodeViewController.swift:
--------------------------------------------------------------------------------
1 | //
2 | // YTScanCodeViewController.swift
3 | // ScanCodeDemo
4 | //
5 | // Created by YTiOSer on 18/5.
6 | // Copyright © 2018 YTiOSer. All rights reserved.
7 | //
8 |
9 | import UIKit
10 | import AVFoundation
11 | import AssetsLibrary
12 |
13 | typealias GetVinOrOemCode = (String, String) -> Void //定义闭包传递选中的分类信息
14 | typealias getCropImageClosure = (UIImage) -> Void
15 |
16 | class YTScanCodeViewController: UIViewController, AVCaptureMetadataOutputObjectsDelegate{
17 |
18 | // AVCaptureSession 是input 与 output 的桥梁,它协调input 到 output的数据传输
19 | var captureSession: AVCaptureSession?
20 | var videoPreviewLayer: AVCaptureVideoPreviewLayer?
21 | var stillImageOutput : AVCaptureStillImageOutput?
22 | var captureView: UIView!
23 | var qrcodeView: YTScanCodeView!
24 | fileprivate var timer: Timer?
25 | fileprivate var getVinOrOemCode:GetVinOrOemCode? //接收上个页面穿过来的闭包
26 |
27 | override func viewDidLoad() {
28 | super.viewDidLoad()
29 |
30 | initCapture()
31 | setupCaptureView()
32 | if let goodSession = captureSession {
33 | goodSession.startRunning() // 启动
34 | timer = Timer.scheduledTimer(timeInterval: 2.0, target: self, selector: #selector(YTScanCodeViewController.scrollScanAction), userInfo: nil, repeats: true)
35 | }
36 | }
37 |
38 | // 隐藏状态栏
39 | override var prefersStatusBarHidden: Bool{
40 | return true
41 | }
42 |
43 | override func didReceiveMemoryWarning() {
44 | super.didReceiveMemoryWarning()
45 | // Dispose of any resources that can be recreated.
46 | }
47 |
48 | }
49 |
50 | // MARK: 逻辑处理
51 | extension YTScanCodeViewController{
52 |
53 | func setBackClosure(code: @escaping GetVinOrOemCode) {
54 | getVinOrOemCode = code
55 | }
56 |
57 | // 定时器控制扫描控件
58 | @objc func scrollScanAction() {
59 | qrcodeView.scrollLabel.isHidden = !qrcodeView.scanButton.isSelected
60 | let qrcodeViewYOffset = kScreenW * 0.75
61 | qrcodeView.scrollLabel.snp.updateConstraints { (make) -> Void in
62 | // error,因为supdate只能更新原有约束的值,并不能加入新的约束
63 | // make.bottom.equalTo(self.qrcodeView.codeView.snp_bottom).offset(-10)
64 | make.top.equalTo(self.qrcodeView.codeView.snp.top).offset(qrcodeViewYOffset - 5)
65 | make.centerX.equalTo(self.qrcodeView.codeView.snp.centerX)
66 | make.width.equalTo(self.qrcodeView.codeView.snp.width)
67 | make.height.equalTo(2)
68 | }
69 | UIView.animate(withDuration: 1.9, animations: { () -> Void in
70 | self.view.layoutIfNeeded()
71 | }) { (_) -> Void in
72 | self.qrcodeView.scrollLabel.snp.updateConstraints { (make) -> Void in
73 | make.top.equalTo(self.qrcodeView.codeView.snp.top).offset(5)
74 | }
75 | }
76 | }
77 |
78 | func cropImageVC(_ img: UIImage) {
79 | //在这里可对图片进行裁剪等操作, 然后使用如百度OCR 慧视等第三方识别图片
80 | //裁剪可参考我的另一篇文章 https://github.com/YTiOSer/CropImage
81 | self.getVinOrOemCode!("vin", "图片识别需要使用第三方工具,这里给出入口")
82 | }
83 |
84 | // MARK:
85 | func fromAlbum() {
86 | //判断设置是否支持图片库
87 | if UIImagePickerController.isSourceTypeAvailable(.photoLibrary){
88 | //初始化图片控制器
89 | let picker = UIImagePickerController()
90 | //设置代理
91 | picker.delegate = self //指定图片控制器类型
92 | picker.sourceType = UIImagePickerControllerSourceType.photoLibrary
93 | //设置是否允许编辑
94 | picker.allowsEditing = false
95 |
96 | //弹出控制器,显示界面
97 | self.present(picker, animated: true, completion: {
98 | () -> Void in
99 | })
100 | }else{
101 | print("读取相册错误")
102 | }
103 | }
104 |
105 | }
106 |
107 | // MARK: 捕获 Capture
108 | extension YTScanCodeViewController{
109 |
110 | // 初始化视频捕获
111 | private func initCapture() {
112 | // 代表抽象的硬件设备,这里传入video
113 | let captureDevice = AVCaptureDevice.default(for: .video)
114 | // 这里代表输入设备(可以是它的子类),它配置抽象硬件设备的ports。
115 | var captureInput:AVCaptureDeviceInput?
116 | if captureDevice == nil{return}
117 | do {
118 | captureInput = try AVCaptureDeviceInput(device: captureDevice!) as AVCaptureDeviceInput
119 | } catch let error as NSError {
120 | print(error)
121 | return
122 | }
123 | // input和output的桥梁,它协调着intput到output的数据传输.(见字意,session-会话)
124 | captureSession = AVCaptureSession()
125 | if kScreenH < 500 {
126 | captureSession!.sessionPreset = .vga640x480//AVCaptureSessionPreset640x480
127 | }else{
128 | captureSession!.sessionPreset = AVCaptureSession.Preset.high
129 | }
130 | captureSession!.addInput(captureInput!)
131 | // 限制扫描区域http://blog.csdn.net/lc_obj/article/details/41549469
132 | let windowSize:CGSize = UIScreen.main.bounds.size;
133 | let scanSize:CGSize = CGSize(width: windowSize.width*3/4, height: windowSize.width*3/4)
134 | var scanRect:CGRect = CGRect.init(x: (windowSize.width-scanSize.width)/2, y: (windowSize.height-scanSize.height)/2 - 45, width: scanSize.width, height: scanSize.height)
135 | //计算rectOfInterest 注意x,y交换位置
136 | scanRect = CGRect(x: scanRect.origin.y/windowSize.height, y: scanRect.origin.x/windowSize.width, width: scanRect.size.height/windowSize.height, height: scanRect.size.width/windowSize.width)
137 | // 输出流 它代表输出数据,管理着输出到一个movie或者图像。
138 | let captureMetadataOutput = AVCaptureMetadataOutput()
139 | //设置可探测区域
140 | captureMetadataOutput.rectOfInterest = scanRect
141 | captureSession!.addOutput(captureMetadataOutput)
142 | // 添加的队列按规定必须是串行
143 | captureMetadataOutput.setMetadataObjectsDelegate(self, queue: DispatchQueue.main)
144 | // 指定信息类型,QRCode
145 | captureMetadataOutput.metadataObjectTypes = [.ean8, .ean13, .code39, .code93, .code128, .qr]
146 |
147 | stillImageOutput = AVCaptureStillImageOutput()
148 | stillImageOutput!.outputSettings = [AVVideoCodecKey : AVVideoCodecJPEG]
149 | captureSession!.addOutput(stillImageOutput!)
150 | // 用这个预览图层和图像信息捕获会话(session)来显示视频
151 | videoPreviewLayer = AVCaptureVideoPreviewLayer(session: captureSession!)
152 | videoPreviewLayer!.videoGravity = AVLayerVideoGravity.resizeAspectFill
153 | videoPreviewLayer!.frame = CGRect(x: 0, y: 0, width: kScreenW, height: kScreenH)
154 | view.layer.addSublayer(videoPreviewLayer!)
155 | }
156 |
157 | // 关闭捕获
158 | fileprivate func stopCapture() {
159 | if captureSession != nil {
160 | captureSession!.stopRunning()
161 | captureView.removeFromSuperview()
162 | }
163 | }
164 |
165 | // MARK: - AVCaptureMetadataOutputObjectsDelegate
166 | func metadataOutput(_ output: AVCaptureMetadataOutput, didOutput metadataObjects: [AVMetadataObject], from connection: AVCaptureConnection) {
167 | if qrcodeView.currentScanMode != ScanModelState.kScanDimensionCode {
168 | return ;
169 | }
170 | if metadataObjects == nil || metadataObjects.count == 0 {
171 | captureView!.frame = CGRect.zero
172 | return
173 | }
174 | // 刷取出来的数据
175 | for metadataObject in metadataObjects {
176 | if metadataObject.type == .qr || metadataObject.type == .ean8 || metadataObject.type == .ean13 || metadataObject.type == .code39 || metadataObject.type == .code93 || metadataObject.type == .code128 {
177 | let metadata = metadataObject as? AVMetadataMachineReadableCodeObject
178 | // 元数据对象就会被转化成图层的坐标
179 | let codeCoord = videoPreviewLayer?.transformedMetadataObject(for: metadata!) as? AVMetadataMachineReadableCodeObject
180 | if codeCoord != nil{
181 | captureView?.frame = codeCoord!.bounds
182 | }
183 | if metadata?.stringValue != nil {
184 | self.captureSession?.stopRunning()
185 | self.qrcodeView.removeFromSuperview()
186 | self.stopCapture()
187 | self.dismiss(animated: true, completion: nil)
188 | self.getVinOrOemCode!("oem", metadata!.stringValue!)
189 | }
190 | }
191 | }
192 | }
193 |
194 | // MARK: 处理拍照
195 | private func didPressTakePhoto(){
196 | if let videoConnection = stillImageOutput?.connection(with: .video){
197 | videoConnection.videoOrientation = AVCaptureVideoOrientation.portrait
198 | stillImageOutput?.captureStillImageAsynchronously(from: videoConnection, completionHandler: {
199 | (sampleBuffer, error) in
200 | if sampleBuffer != nil {
201 | self.stopCapture()
202 | let imageData = AVCaptureStillImageOutput.jpegStillImageNSDataRepresentation(sampleBuffer!)
203 | let dataProvider = CGDataProvider(data: imageData! as CFData)
204 | let cgImageRef = CGImage(jpegDataProviderSource: dataProvider!, decode: nil, shouldInterpolate: true, intent: .defaultIntent)
205 | var captureImage = UIImage( cgImage: cgImageRef!)
206 | captureImage = captureImage.imageByRotate(degreesToRadians(-90.0), true)!
207 | var f: CGRect = CGRect.zero
208 | let scale = captureImage.size.height / kScreenH;
209 | let w = self.qrcodeView.codeView.frame.width * scale;
210 | let h = self.qrcodeView.codeView.frame.height * scale;
211 | //big
212 | let w2 = captureImage.size.width;
213 | let h2 = captureImage.size.height;
214 | f.origin.y = (h2 - h) / 2.0;
215 | f.origin.x = (w2-w)/2.0;
216 | f.size.height = h;
217 | f.size.width = w;
218 | let image = captureImage.cropWithCropRect(f)
219 | self.qrcodeView.imageClipView.image = image
220 | if self.qrcodeView.imageClipView.isHidden == false
221 | {
222 | let img = self.qrcodeView.imageClipView.image
223 | if self.qrcodeView.imageClipView.image != nil
224 | {
225 | //第三方识别图片
226 | self.getVinOrOemCode!("vin", "图片识别需要使用第三方工具,这里给出入口")
227 | }
228 | }
229 | }
230 | })
231 | }
232 | }
233 |
234 | }
235 |
236 | // MARK: UI
237 | extension YTScanCodeViewController{
238 |
239 | // MARK: - View Setup
240 | private func setupCaptureView() {
241 | // 创建系统自动捕获框
242 | captureView = {
243 | let captureView = UIView()
244 | captureView.layer.borderColor = UIColor.green.cgColor
245 | captureView.layer.borderWidth = 2
246 | self.view.addSubview(captureView)
247 | self.view.bringSubview(toFront: captureView)
248 | return captureView
249 | }()
250 |
251 | // 扫一扫的图片
252 | qrcodeView = {
253 | let codeView = YTScanCodeView(frame: CGRect.zero)
254 | weak var weakSelf = self
255 | codeView.didClickedBackButtonClosure = {
256 | weakSelf!.stopCapture()
257 | weakSelf!.qrcodeView.removeFromSuperview()
258 | weakSelf!.dismiss(animated: true, completion: nil)
259 | }
260 | codeView.didClickedPhonoButtonClosure = {
261 | weakSelf!.didPressTakePhoto()
262 | }
263 | codeView.didClickedRemakeButtonClosure = {
264 | if let session = weakSelf!.captureSession
265 | {
266 | session.startRunning()
267 | weakSelf!.captureView.removeFromSuperview()
268 | weakSelf!.qrcodeView.resetButtonTitle()//清空原来识别的按钮上的文字
269 | }
270 | }
271 | // 确认
272 | codeView.didClickedOKVinCodeButtonClosure = {(vidCode) -> Void in
273 | weakSelf!.qrcodeView.removeFromSuperview()
274 | weakSelf!.stopCapture()
275 | weakSelf!.dismiss(animated: true, completion: nil)
276 | weakSelf!.getVinOrOemCode!("vin", vidCode)
277 | }
278 |
279 | self.view.addSubview(codeView)
280 | codeView.frame = CGRect(x: 0, y: 0, width: kScreenW, height: kScreenH)//self.view.frame
281 |
282 | //从相册中选择图像
283 | codeView.didClickedPhotoAlbumButtonClosure = {
284 | weakSelf!.stopCapture()
285 | weakSelf!.fromAlbum()
286 | }
287 |
288 | return codeView
289 | }()
290 |
291 | }
292 |
293 | }
294 |
295 | // MARK: UIImagePickerControllerDelegate
296 | extension YTScanCodeViewController: UIImagePickerControllerDelegate, UINavigationControllerDelegate{
297 |
298 | //选择图片成功后代理
299 | func imagePickerController(_ picker: UIImagePickerController,
300 | didFinishPickingMediaWithInfo info: [String : Any]) {
301 | //查看info对象
302 | print(info)
303 |
304 | let image = info[UIImagePickerControllerOriginalImage] as! UIImage
305 |
306 | //图片控制器退出
307 | picker.dismiss(animated: true, completion: {
308 | () -> Void in
309 |
310 | })
311 | self.cropImageVC(image)
312 | }
313 |
314 | public func imagePickerControllerDidCancel(_ picker: UIImagePickerController) {
315 |
316 | picker.dismiss(animated: true, completion: {
317 | () -> Void in
318 |
319 | })
320 | captureSession!.startRunning()
321 | }
322 |
323 | }
324 |
325 |
326 |
327 |
328 |
329 |
--------------------------------------------------------------------------------
/ScanCodeDemo/ScanCode/view/YTScanCodeView.swift:
--------------------------------------------------------------------------------
1 | //
2 | // YTScanCodeView.swift
3 | // ScanCodeDemo
4 | //
5 | // Created by YTiOSer on 18/5.
6 | // Copyright © 2018 YTiOSer. All rights reserved.
7 | //
8 |
9 | import UIKit
10 |
11 | let kScreenW = ScreenWidth //UIScreen.main.bounds.size.width
12 | let kScreenH = ScreenHeight //UIScreen.main.bounds.size.height
13 | let kScanVinCodeNotification = "ScanVinCodeNotification" //通知
14 |
15 | typealias getVinCode = (String) -> Void //定义闭包传递选中的分类信息
16 | typealias clickBtnClouse = () -> Void
17 |
18 | /**
19 | 扫描模式
20 | - kScanDimensionCode: 二维码 一维码
21 | - kScanVinCode : VIN码
22 | - kOther: 其他
23 | */
24 | public enum ScanModelState: Int {
25 | case kScanDimensionCode = 1
26 | case kScanVinCode = 2
27 | case kOther = 3
28 | }
29 |
30 | class YTScanCodeView: UIView {
31 |
32 | /**
33 | - kBack 返回按钮
34 | - kDimensionCode 二维码
35 | - kVinCode Vin 码
36 | - kPhoto 拍照按钮
37 | - kRemakePhono 重拍按钮
38 | - kOKVinCode 确定按钮
39 | - kPhotoAlbum 相册
40 | */
41 | enum ButtonTagValue:Int {
42 | case kBack = 1000
43 | case kDimensionCode = 1001
44 | case kVinCode = 1002
45 | case kPhoto = 1003
46 | case kRemakePhono = 1004
47 | case kOKVinCode = 1005
48 | case kPhotoAlbum = 1006
49 | }
50 |
51 | var codeView: UIImageView! //扫描框
52 | var scrollLabel: UIImageView! //扫描线
53 | var toolbarView: UIView!
54 |
55 | var messageLabel: UILabel! //提示文字label
56 | var backButton: UIButton! // 返回
57 | var photoAlbumButton: UIButton! // 相册
58 | var vinButton: UIButton! //VIN
59 | var scanButton: UIButton! //二维码
60 | var photoButton: UIButton! //拍照
61 | var remakeButton: UIButton! //重拍
62 | var okVinCodeButton: UIButton! //确定
63 |
64 | var currentScanMode: ScanModelState! //扫码模式
65 |
66 | var arrayKeyboardButton = [UIButton]() //自定义键盘
67 | var toolbarVertical: UIView!
68 | var imageClipView:UIImageView!
69 |
70 | fileprivate var alphaLeftBGView: UIView!//左边半透明
71 | fileprivate var alphaBottomBGView: UIView!//底部半透明
72 | fileprivate var alphaTopBGView: UIView!//顶部半透明
73 | fileprivate var vinCodeView: YTNoMenuTextField!
74 | fileprivate var keyBoardBGView: UIView!
75 |
76 | var didClickedBackButtonClosure: clickBtnClouse? //返回闭包
77 | var didClickedPhonoButtonClosure: clickBtnClouse? //拍照闭包
78 | var didClickedRemakeButtonClosure: clickBtnClouse? //重拍闭包
79 | var didClickedOKVinCodeButtonClosure: getVinCode? //VIN确定闭包
80 | var didClickedPhotoAlbumButtonClosure: clickBtnClouse? //相册闭包
81 |
82 | override init(frame: CGRect) {
83 | super.init(frame:frame)
84 |
85 | setUpCustomView()
86 | editVINCode(isEdit: false)
87 | photoAlbumButton.isHidden = true
88 |
89 | self.backgroundColor = UIColor.black.withAlphaComponent(0.3) //alpha
90 |
91 | NotificationCenter.default.addObserver(self, selector: #selector(YTScanCodeView.getVinCodeResult(notificaion:)), name: NSNotification.Name(rawValue: kScanVinCodeNotification), object: nil)
92 | }
93 |
94 | required init?(coder aDecoder: NSCoder) {
95 | fatalError("init(coder:) has not been implemented")
96 | }
97 |
98 | }
99 |
100 |
101 | extension YTScanCodeView{
102 |
103 | // MARK: -处理按钮点击事件
104 | @objc func didClickedButtonAction(btn: UIButton) {
105 |
106 | vinCodeView.isHidden = true
107 | switch btn.tag {
108 | case ButtonTagValue.kBack.rawValue :
109 | if let sureClosure = didClickedBackButtonClosure {
110 | sureClosure()
111 | }
112 | case ButtonTagValue.kDimensionCode.rawValue ://点击扫描二维码按钮
113 | scrollLabel.isHidden = false
114 | scanButton.isSelected = true
115 | vinButton.isSelected = false
116 | setScanModelState(scanType: .kScanDimensionCode)
117 | case ButtonTagValue.kPhoto.rawValue ://点击拍照按钮
118 | if let sureClosure = didClickedPhonoButtonClosure {
119 | sureClosure()
120 | self.editVINCode(isEdit: true)
121 | }
122 | case ButtonTagValue.kVinCode.rawValue ://点击扫描vin码按钮
123 | scrollLabel.isHidden = true
124 | scanButton.isSelected = false
125 | vinButton.isSelected = true
126 | setScanModelState(scanType: .kScanVinCode)
127 | case ButtonTagValue.kRemakePhono.rawValue ://点击重拍按钮
128 | if let sureClosure = didClickedRemakeButtonClosure {
129 | sureClosure()
130 | self.editVINCode(isEdit: false)
131 | }
132 | case ButtonTagValue.kOKVinCode.rawValue :
133 | self.didClickedOKVinCodeButtonClosure!(vinCodeView.text!)
134 | //从相册中选择
135 | case ButtonTagValue.kPhotoAlbum.rawValue:
136 | if let sureClosure = didClickedPhotoAlbumButtonClosure {
137 | sureClosure()
138 | }
139 | default :
140 | break
141 | }
142 | }
143 |
144 | //闭包变量
145 | func setBackClosure(SortInfo:@escaping getVinCode) {
146 | didClickedOKVinCodeButtonClosure = SortInfo
147 | }
148 |
149 | /**
150 | * 二维码扫描&Vin码扫描
151 | */
152 | internal func setScanModelState( scanType: ScanModelState) -> Void {
153 | currentScanMode = scanType
154 | switch scanType {
155 | case .kScanDimensionCode:
156 | // 隐藏拍照按钮
157 | photoButton.isHidden = true
158 | //设置按钮位置
159 | backButton.frame = CGRect(x: 10, y: 20, width: 32, height: 32)
160 | backButton.transform = .identity
161 | scanButton.transform = .identity
162 | vinButton.transform = .identity
163 | let scanSize:CGSize = CGSize(width: kScreenW*3/4, height: kScreenW*3/4)
164 | codeView.image = UIImage(named: "pick_bg")
165 | codeView.frame = CGRect(x: 0, y: 0, width: scanSize.width, height: scanSize.height)
166 | codeView.center = CGPoint(x: UIScreen.main.bounds.midX, y: UIScreen.main.bounds.midY - 45)
167 | messageLabel.isHidden = false
168 | self.editVINCode(isEdit: false)
169 | // 隐藏 冲相册选择按钮
170 | photoAlbumButton.isHidden = true
171 |
172 | case .kScanVinCode:
173 | photoButton.isHidden = false //显示拍照按钮
174 | photoAlbumButton.isHidden = false
175 | let rotation90 = CGAffineTransform(rotationAngle: CGFloat(degreesToRadians(90.0)))
176 | scanButton.transform = rotation90
177 | vinButton.transform = rotation90
178 | var l:CGFloat! = 160.0 + 80.0
179 | if kScreenH > 568 {
180 | l = 230 + 80.0
181 | }
182 | codeView.image = UIImage(named: "pick_vin_bg")
183 | codeView.frame = CGRect(x: 0, y: 0, width: 60, height: kScreenH - l)
184 | codeView.center = CGPoint(x: UIScreen.main.bounds.midX, y: UIScreen.main.bounds.midY - 30)
185 | messageLabel.isHidden = true
186 | self.imageClipView.frame = CGRect(x: (kScreenW - self.codeView.frame.width - 2), y: ((kScreenH - self.codeView.frame.height) / 2), width: self.codeView.frame.width, height: self.codeView.frame.height)
187 | default:
188 | break
189 | }
190 | }
191 |
192 | }
193 |
194 | // MARK: UI
195 | extension YTScanCodeView{
196 |
197 | /**
198 | * 布局用户视图
199 | */
200 | private func setUpCustomView() {
201 | //初始化二维码为二维扫描模式
202 | currentScanMode = .kScanDimensionCode
203 |
204 | codeView = {
205 | let imageView = UIImageView()
206 | imageView.image = UIImage(named: "pick_bg")
207 | self.addSubview(imageView)
208 | let scanSize:CGSize = CGSize(width: kScreenW*3/4, height: kScreenW*3/4)
209 | imageView.frame = CGRect(x: 0, y: 0, width: scanSize.width, height: scanSize.height)
210 | imageView.center = CGPoint(x: UIScreen.main.bounds.midX, y: UIScreen.main.bounds.midY - 45)
211 |
212 | return imageView
213 | }()
214 | // #0016898/0017158、0017157 add by whq at 2016-04-05 begin
215 | addAlphaBGView()
216 | // #0016898/0017158、0017157 add by whq at 2016-04-05 end
217 | messageLabel = {
218 | let label = UILabel()
219 | label.text = "将二维码放入框内,即可自动扫描"
220 | label.textColor = UIColor.white
221 | label.font = UIFont.systemFont(ofSize: 13.0)
222 | label.textAlignment = .center
223 | self.addSubview(label)
224 | label.frame = CGRect(x: 0, y: codeView.frame.maxY, width: kScreenW, height: 15)
225 | return label
226 | }()
227 | scrollLabel = {
228 | let imageView = UIImageView()
229 | imageView.image = UIImage(named: "line")
230 | imageView.isHidden = true
231 | self.addSubview(imageView)
232 | imageView.frame = CGRect(x: codeView.frame.minX, y: codeView.frame.minY, width: codeView.frame.width, height: 2)
233 | return imageView
234 | }()
235 | toolbarView = {
236 | let toolbar = UIView()
237 | toolbar.backgroundColor = UIColor.black
238 | toolbar.frame = CGRect(x: 0, y: kScreenH - 60, width: kScreenW, height: 60)
239 | self.addSubview(toolbar)
240 | return toolbar
241 | }()
242 | scanButton = {
243 | let button = UIButton(type: .custom)
244 | button.setImage(UIImage(named: "scan_dimension_code"), for: UIControlState.normal)
245 | button.setImage(UIImage(named: "scan_dimension_code_pre"), for: UIControlState.selected)
246 | button.addTarget(self, action: #selector(YTScanCodeView.didClickedButtonAction(btn:)), for: .touchUpInside)
247 | button.tag = ButtonTagValue.kDimensionCode.rawValue
248 | toolbarView.addSubview(button)
249 | button.frame = CGRect.init(x: 10, y: 0, width: 60, height: 60)
250 | button.isSelected = true
251 | return button
252 | }()
253 | photoButton = {
254 | let button = UIButton(type: UIButtonType.custom)
255 | button.setImage(UIImage(named: "scan_capture"), for: UIControlState.normal)
256 | button.addTarget(self, action: #selector(YTScanCodeView.didClickedButtonAction(btn:)), for: .touchUpInside)
257 | button.tag = ButtonTagValue.kPhoto.rawValue
258 | toolbarView.addSubview(button)
259 | button.isHidden = true
260 | button.frame = CGRect(x: kScreenW/2-30, y: 0, width: 60, height: 60)
261 | return button
262 | }()
263 | vinButton = {
264 | let button = UIButton(type: UIButtonType.custom)
265 | button.setImage(UIImage(named: "scan_vin_code"), for: UIControlState.normal)
266 | button.setImage(UIImage(named: "scan_vin_code_pre"), for: UIControlState.selected)
267 | button.addTarget(self, action: #selector(YTScanCodeView.didClickedButtonAction(btn:)), for: .touchUpInside)
268 | button.tag = ButtonTagValue.kVinCode.rawValue
269 | toolbarView.addSubview(button)
270 | button.frame = CGRect(x: kScreenW-70, y: 0, width: 60, height: 60)
271 | return button
272 | }()
273 | // 初始化横屏的工具栏
274 | toolbarVertical = {
275 | let toolbar = UIView()
276 | toolbar.backgroundColor = UIColor.black
277 | toolbar.frame = CGRect(x: 0, y: 0, width: 50, height: kScreenH)
278 | toolbar.isHidden = true
279 | self.addSubview(toolbar)
280 | return toolbar
281 | }()
282 | remakeButton = {
283 | let button = UIButton(type: UIButtonType.custom)
284 | button.setTitle("重 拍", for: .normal)
285 | button.setTitleColor(UIColor.yellow, for: .normal)
286 | button.backgroundColor = UIColor.black
287 | button.addTarget(self, action: #selector(YTScanCodeView.didClickedButtonAction(btn:)), for: .touchUpInside)
288 | button.tag = ButtonTagValue.kRemakePhono.rawValue
289 | button.frame = CGRect(x: -20, y: kScreenH/4 - 100, width: 80, height: 40)
290 | button.transform = CGAffineTransform(rotationAngle: degreesToRadians(90))
291 | toolbarVertical.addSubview(button)
292 | return button
293 | }()
294 | okVinCodeButton = {
295 | let button = UIButton(type: UIButtonType.custom)
296 | button.setTitle("确 定", for: .normal)
297 | button.setTitleColor(UIColor.green, for: .normal)
298 | button.backgroundColor = UIColor.black
299 | button.addTarget(self, action: #selector(YTScanCodeView.didClickedButtonAction(btn:)), for: .touchUpInside)
300 | button.tag = ButtonTagValue.kOKVinCode.rawValue
301 | button.frame = CGRect(x: -20, y: kScreenH/4 * 3 + 20, width: 80, height: 40)
302 | button.transform = CGAffineTransform(rotationAngle: degreesToRadians(90))
303 | toolbarVertical.addSubview(button)
304 | return button
305 | }()
306 | imageClipView = {
307 | let imageView = UIImageView()
308 | self.addSubview(imageView)
309 | imageView.isHidden = true
310 | return imageView
311 | }()
312 | self.virtualKeyboard()
313 | backButton = {
314 | let button = UIButton(type: UIButtonType.custom)
315 | let avatarImage = UIImage(named: "app_b_back")
316 | button.setImage(avatarImage, for: UIControlState.normal)
317 | button.frame = CGRect(x: 10, y: 10, width: 32, height: 32)
318 | button.layer.cornerRadius = 16.0
319 | button.layer.borderWidth = 1.0
320 | button.layer.borderColor = UIColor.clear.cgColor
321 | button.clipsToBounds = true
322 | button.alpha=0.5
323 | button.backgroundColor = UIColor.black
324 | button.addTarget(self, action: #selector(YTScanCodeView.didClickedButtonAction(btn:)), for: .touchUpInside)
325 | button.tag = ButtonTagValue.kBack.rawValue
326 | self.addSubview(button)
327 | return button
328 | }()
329 |
330 | photoAlbumButton = {
331 | let button = UIButton(type: UIButtonType.custom)
332 | button.setTitle("相册", for: .normal)
333 | button.setTitleColor(UIColor.white, for: .normal)
334 | button.backgroundColor = UIColor.clear
335 | button.addTarget(self, action: #selector(YTScanCodeView.didClickedButtonAction(btn:)), for: .touchUpInside)
336 | button.tag = ButtonTagValue.kPhotoAlbum.rawValue
337 | button.frame = CGRect(x: kScreenW-80, y: 10, width: 80, height: 25)
338 | // 隐藏 冲相册选择按钮
339 | button.isHidden = true
340 | self.addSubview(button)
341 | return button
342 | }()
343 | }
344 | /**
345 | * 设置透明度
346 | **/
347 | private func addAlphaBGView()
348 | {
349 | alphaTopBGView = UIView()
350 | alphaTopBGView.backgroundColor = UIColor.black
351 | alphaTopBGView.alpha = 0.5
352 | self.addSubview(alphaTopBGView)
353 | alphaTopBGView.snp.makeConstraints { (make) in
354 | make.top.left.right.equalTo(self)
355 | make.bottom.equalTo(codeView.snp.top)
356 | }
357 | alphaLeftBGView = UIView()
358 | alphaLeftBGView.backgroundColor = UIColor.black
359 | alphaLeftBGView.alpha = 0.5
360 | self.addSubview(alphaLeftBGView)
361 | alphaLeftBGView.snp.makeConstraints { (make) in
362 | make.top.equalTo(codeView.snp.top)
363 | make.left.equalTo(self.snp.left)
364 | make.right.equalTo(codeView.snp.left)
365 | make.bottom.equalTo(codeView.snp.bottom)
366 | }
367 | alphaBottomBGView = UIView()
368 | alphaBottomBGView.backgroundColor = UIColor.black
369 | alphaBottomBGView.alpha = 0.5
370 | self.addSubview(alphaBottomBGView)
371 | alphaBottomBGView.snp.makeConstraints { (make) in
372 | make.top.equalTo(codeView.snp.bottom)
373 | make.left.right.bottom.equalTo(self)
374 | // make.bottom.equalTo(self.snp.bottom)
375 | }
376 | let alphaRightBGView = UIView()
377 | alphaRightBGView.backgroundColor = UIColor.black
378 | alphaRightBGView.alpha = 0.5
379 | self.addSubview(alphaRightBGView)
380 | alphaRightBGView.snp.makeConstraints { (make) in
381 | make.top.equalTo(codeView.snp.top)
382 | make.right.equalTo(self.snp.right)
383 | make.left.equalTo(codeView.snp.right)
384 | make.bottom.equalTo(codeView.snp.bottom)
385 | }
386 | }
387 |
388 | }
389 |
390 | // MARK: VIN码
391 | extension YTScanCodeView{
392 |
393 | //MARK: - 创建VIN码
394 | /// A ** initvinCode** function
395 | private func initVINCode() -> Void {
396 |
397 | let buttonHeight: CGFloat = 40.0
398 | var buttonPosX: CGFloat = 220.0
399 |
400 | if kScreenH == 667 {
401 | buttonPosX = kScreenW/3*2+5
402 | }
403 | if kScreenH > 667 { //736
404 | buttonPosX = kScreenW/3*2+10
405 | }
406 | let rotation90: CGAffineTransform = CGAffineTransform(rotationAngle: degreesToRadians(90.0))
407 | let point = CGPoint.init(x: buttonPosX + 30, y: kScreenH / 2)
408 | keyBoardBGView = UIView()
409 | keyBoardBGView.frame = CGRect(x: 50, y: 0, width: buttonPosX - buttonHeight - 20, height: kScreenH)
410 | keyBoardBGView.backgroundColor = UIColor.gray
411 | keyBoardBGView.isHidden = true
412 | self.addSubview(keyBoardBGView)
413 | vinCodeView = YTNoMenuTextField()
414 | vinCodeView.isHidden = true
415 | vinCodeView.backgroundColor = UIColor.white
416 | vinCodeView.frame = CGRect(x: 0, y: 0, width: kScreenH - 50, height: buttonHeight)
417 | vinCodeView.center = point
418 | vinCodeView.transform = rotation90
419 | vinCodeView.textAlignment = .center
420 | vinCodeView.font = UIFont.systemFont(ofSize: 25.0)
421 | vinCodeView.becomeFirstResponder()
422 | vinCodeView.clearButtonMode = .whileEditing
423 | vinCodeView.inputView = UIView.init(frame: CGRect.zero)
424 | self.addSubview(vinCodeView)
425 | }
426 |
427 | // MARK: -
428 | func editVINCode(isEdit: Bool) {
429 | for btn in arrayKeyboardButton {
430 | btn.isHidden = !isEdit
431 | }
432 | toolbarVertical.isHidden = !isEdit
433 | self.toolbarView.isHidden = isEdit
434 | self.toolbarVertical.isHidden = !isEdit
435 | self.imageClipView.isHidden = !isEdit
436 | vinCodeView.isHidden = !isEdit
437 | keyBoardBGView.isHidden = !isEdit
438 | backButton.isHidden = isEdit
439 | photoAlbumButton.isHidden = isEdit
440 |
441 | }
442 | // MARK: - 获取VIN 码
443 | func getVINCode() -> String {
444 | return vinCodeView.text!
445 | }
446 | //重拍的时候,把按钮上显示的文字设置为0
447 | func resetButtonTitle(){
448 | vinCodeView.text = ""
449 | }
450 | //MARK:响应扫描vin码后的消息通知
451 | @objc func getVinCodeResult(notificaion: NSNotification)
452 | {
453 |
454 | let dic = notificaion.object as? NSDictionary
455 | if dic?["errMsg"] as? String == "success"
456 | {
457 | guard let word = dic?["word"] as? String else{return}
458 | if word.isEmpty != true
459 | {
460 | DispatchQueue.main.async(execute: {//在主线程里刷新界面
461 | self.vinCodeView.text = word
462 | })
463 | } else{
464 | DispatchQueue.main.async(execute: {//在主线程里刷新界面
465 | self.showToast("识别失败,请重新拍摄")
466 | })
467 | }
468 | }else{
469 | DispatchQueue.main.async(execute: {//在主线程里刷新界面
470 | self.showToast("识别失败,请重新拍摄")
471 | })
472 |
473 | }
474 | }
475 |
476 | }
477 |
478 | // MARK: 虚拟键盘
479 | extension YTScanCodeView{
480 |
481 | // MARK: - 虚拟键
482 | private func virtualKeyboard() -> Void {
483 |
484 | initVINCode()
485 |
486 | let arrayKeyCharacter = ["0","1","2","3","4","5","6","7","8","9","", "Q","W","E","R","T","Y","U","I","O","P", "" ,"A","S","D","F","G","H","J","K","L", "","Z", "X","C","V","B","N","M"]
487 |
488 | var interval: CGFloat = 5.0
489 | var buttonWidth: CGFloat = 40
490 | var buttonTempWidth: CGFloat = 40
491 | var buttonHeight:CGFloat = 30
492 | var buttonPosX: CGFloat = 170.0
493 | var buttonPosY: CGFloat = (kScreenH - 445 - 44)/2
494 | var buttonsIntervals: CGFloat = 9.0
495 | if (kScreenH == 667 || kScreenH > 667) {
496 | interval = 8.0
497 | buttonPosX = kScreenW/3*2-55
498 | buttonWidth = 48
499 | buttonTempWidth = 48
500 | buttonHeight = 35
501 | buttonPosY = (kScreenH - buttonWidth * 11 - interval * 10)/2
502 | buttonsIntervals = 12.0
503 | }
504 | for charValue in arrayKeyCharacter {
505 | if charValue == "Q" {
506 | buttonPosX -= buttonWidth
507 | buttonPosY = (kScreenH - buttonWidth * 11 - interval * 10)/2
508 | }
509 | if charValue == "A" {
510 | buttonPosX -= buttonWidth
511 | buttonPosY = (kScreenH - buttonWidth * 11 - interval * 10)/2 + 3//按钮向下移动3个位置,进行微调
512 | buttonTempWidth = buttonWidth + (buttonWidth + interval) / 10
513 | }
514 | if charValue == "Z" {
515 | buttonPosX -= buttonWidth + buttonsIntervals
516 | buttonPosY = (kScreenH - buttonWidth * 11 - interval * 10)/2 + 14//按钮向下移动12个位置,进行微调
517 | buttonTempWidth = buttonWidth + (buttonWidth + interval) * 4 / 7
518 | }
519 | let rotation90: CGAffineTransform = CGAffineTransform(rotationAngle: degreesToRadians(90.0))
520 | let frame: CGRect = CGRect(x: buttonPosX, y: buttonPosY, width: buttonTempWidth, height: buttonHeight)
521 | let button = UIButton(type: UIButtonType.custom)
522 | button.frame = frame
523 | button.transform = rotation90
524 | button.setTitle(charValue, for: .normal)
525 | button.setTitleColor(UIColor.black, for: .normal)
526 | button.layer.cornerRadius = 3.0
527 | button.layer.masksToBounds = false
528 | button.backgroundColor = UIColor.white
529 | button.titleLabel?.font = UIFont.boldSystemFont(ofSize: 16.0)
530 | button.addTarget(self, action: #selector(YTScanCodeView.didClickedKeyboardButtonAction(btn:)), for: .touchUpInside)
531 | button.tag = 200 + arrayKeyboardButton.count
532 | if arrayKeyboardButton.count == 10 {
533 | button.setImage(UIImage.init(named: "Keyboard_Backspace"), for: .normal)
534 | }
535 | if arrayKeyboardButton.count == 21{
536 | button.setImage(UIImage.init(named: "rewordspace"), for: .normal)
537 | }
538 | if arrayKeyboardButton.count == 31{
539 | button.setImage(UIImage.init(named: "backspace"), for: .normal)
540 | }
541 | self.addSubview(button)
542 | buttonPosY += interval + buttonTempWidth
543 | arrayKeyboardButton.append(button)
544 | }
545 | }
546 |
547 | //MARK: - 虚拟键盘响应事件
548 | @objc func didClickedKeyboardButtonAction(btn: UIButton) {
549 | if btn.tag == 210//删除字符
550 | {
551 | vinCodeView.deleteBackward()
552 | }
553 | else if btn.tag == 221//光标向前移动一个位置
554 | {
555 | var range = vinCodeView.selectedRange()
556 | range.location = range.location - 1
557 | vinCodeView.setSelectedRange(range: range)
558 | }
559 | else if btn.tag == 231//光标向后移动一个位置
560 | {
561 | var range = vinCodeView.selectedRange()
562 | range.location = range.location + 1
563 | vinCodeView.setSelectedRange(range: range)
564 | }else{
565 | if let labCon = btn.titleLabel?.text{
566 | vinCodeView.insertText(labCon)//输入文本
567 | }
568 | }
569 | }
570 |
571 | }
572 |
573 | // MARK: UITextField extension
574 | extension UITextField {
575 | func selectedRange() -> NSRange
576 | {
577 | let beginning = self.beginningOfDocument
578 | let selectedRange = self.selectedTextRange
579 | let selectionStart = selectedRange?.start
580 | let selectionEnd = selectedRange?.end
581 | guard let _ = selectionStart else { return NSRange.init(location: 0, length: 0)}
582 | guard let _ = selectionEnd else { return NSRange.init(location: 0, length: 0)}
583 | let location = self.offset(from: beginning, to: selectionStart!)
584 | let length = self.offset(from: selectionStart!, to: selectionEnd!)
585 | return NSRange.init(location: location, length: length)
586 | }
587 |
588 | func setSelectedRange(range: NSRange)
589 | {
590 | let beginning = self.beginningOfDocument
591 | let startPosition = self.position(from: beginning, offset: range.location)
592 | let endPosition = self.position(from: beginning, offset: range.location + range.length)
593 | guard let _ = startPosition else { return }
594 | guard let _ = endPosition else { return }
595 | let selectionRange = self.textRange(from: startPosition!, to: endPosition!)
596 | self.selectedTextRange = selectionRange
597 | }
598 | }
599 |
600 | // MARK: - CGFloat
601 | public func degreesToRadians (_ angle: CGFloat) -> CGFloat {
602 | return (CGFloat (Double.pi) * angle) / 180.0
603 | }
604 |
605 | // MARK: 屏幕宽高(适配横竖屏)
606 | public var Orientation: UIInterfaceOrientation {
607 | get {
608 | return UIApplication.shared.statusBarOrientation
609 | }
610 | }
611 |
612 | /// 屏幕宽度
613 | public var ScreenWidth: CGFloat {
614 | get {
615 | if UIInterfaceOrientationIsPortrait(Orientation) {
616 | return UIScreen.main.bounds.size.width
617 | } else {
618 | return UIScreen.main.bounds.size.height
619 | }
620 | }
621 | }
622 |
623 | /// 屏幕高度
624 | public var ScreenHeight: CGFloat {
625 | get {
626 | if UIInterfaceOrientationIsPortrait(Orientation) {
627 | return UIScreen.main.bounds.size.height
628 | } else {
629 | return UIScreen.main.bounds.size.width
630 | }
631 | }
632 | }
633 |
634 |
--------------------------------------------------------------------------------