Giter Site home page Giter Site logo

hrqrcodescantool's Introduction

HRQRCodeScanTool

Summary

HRQRCodeScanTool is a lightweight, high cohesion, low couplingpure, pure-Swift tool for QRcode scan.

Description

This tool uses AVFoundation based on Swift4.1 API. It improves the reusability of the code and make the code be easy to maintain and extend in ViewControllers. This tool support not only qrcode but also support .ean13 .ean8 .upce .code39 .code93 .code128 .code39Mod43. Don't run in simulator.

Example

二维码

条码

Requirements

  • Swift 4.1
  • iOS 8.0+
  • Xcode 9.3

Installation

CocoaPods(recommend):

HRQRCodeScanTool is available through CocoaPods. To install it, simply add the following lines to your Podfile:

platform :ios, '8.0'
use_frameworks!

pod 'HRQRCodeScanTool'

Then import header in your code

import HRQRCodeScanTool

Manually

  1. Download and drop HRQRCodeScanTool.swift in your project.
  2. Congratulations!

Usage example

Remember to add this key-value in your info.plist

<key>NSCameraUsageDescription</key>
<string>CameraUsageDescription</string>

CheckCameraAuthauthority

import AVFoundation

let status = AVCaptureDevice.authorizationStatus(for: .video)
if status != .authorized {
         AVCaptureDevice.requestAccess(for: .video) { (flag) in
    }
}

Inited from pure code :

// in ViewController
HRQRCodeScanTool.shared.delegate  = self
HRQRCodeScanTool.shared.beginScanInView(view: view)
......
// scan result will call in  delegate methods 
func scanQRCodeFaild(error: String){
print(error)
}

func scanQRCodeSuccess(resultStrs: [String]){
print(resultStrs.first)
}

Customization Properties

property default value remark
open var isDrawQRCodeRect: Bool true 是否描绘二维码边框 默认true
open var drawRectColor: UIColor UIColor.red 二维码边框颜色 默认红色
open var drawRectLineWith: CGFloat 2 二维码边框线宽 默认2
open var isShowMask: Bool true 是否展示黑色蒙版板层 默认开启
open var maskColor: UIColor Black.alpha 0.5 蒙板层 默认黑色 alpha 0.5
open var centerWidth: CGFloat 200 中心非蒙板区域的宽
open var centerHeight: CGFloat 5.0 中心非蒙板区域的宽
open var centerPosition: CGPoint? nil 中心非蒙板区域的中心点 默认Veiw的中心

Public Methods

open func beginScanInView(view: UIView)
open func setInterestRect(originRect: CGRect)
open func stopScan()

Mentions

If you use it under opaque navigation bars, the preview layer will move down the navigation bar height, so is open var centerPosition: CGPoint?.

Author

CoderHRXu Mail: [email protected]

Blog: www.akpop.top Relevant article: https://www.jianshu.com/p/e16a4380d7b2

https://juejin.im/post/5ad9b34851882567361479aa

http://www.akpop.top/2018/04/20/Swift4QRCodeTool/

License

LICENSE

HRQRCodeScanTool is released under the MIT and Anti-996 license. See the LICENSE file for more info.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.