Swift(12):QRScannerQRコードパッケージの概要



Swift Qrscanner Qr Code Package Summary



例1

// // scanQRViewController.swift // QRCode // // Created by HMC on 16/8/15. // Copyright © 2016 SKing. All rights reserved. // import UIKit import AVFoundation class scanQRViewController: UIViewController { //lazy var session = AVCaptureSession() /// scan grid distance the length of the bottom of the box @IBOutlet weak var lineToBottom: NSLayoutConstraint! /// Background of the scan box and scan line View @IBOutlet weak var scanBackground: UIView! / / Scan box @IBOutlet weak var scanDeadLine: UIImageView! override func viewDidLoad() { super.viewDidLoad() // Do any additional setup after loading the view. // startScan() SQRCode.sharedObject.scanQRCode(view) { (result:String) in Let alert = UIAlertController(title: 'recognition result', message: result, preferredStyle: .Alert) Let action = UIAlertAction(title: 'good', style: .Default, handler: { (action: UIAlertAction) in self.dismissViewControllerAnimated(true, completion: nil) }) alert.addAction(action) self.presentViewController(alert, animated: true, completion: nil) } } override func viewDidAppear(animated: Bool) { super.viewDidAppear(animated) startAnimationOfLine() } } // MARK: - related UI and animation extension scanQRViewController{ /** Animated settings */ func startAnimationOfLine() { / / Initialize the position of the line lineToBottom.constant = scanBackground.frame.height loadViewIfNeeded() / / Set the end position lineToBottom.constant = -scanBackground.frame.height / / Set the animation UIView.animateWithDuration(3, animations: { / / Set the repeat UIView.setAnimationRepeatCount(MAXFLOAT) self.view.layoutIfNeeded() }) { (bool : Bool) in Print(' ') } } }

ケース2

// // showQRController.swift // QRCode // // Created by HMC on 16/8/11. // Copyright © 2016 SKing. All rights reserved. // import UIKit import CoreImage class showQRController: UIViewController { @IBOutlet weak var QRImageView: UIImageView! override func viewDidLoad() { super.viewDidLoad() QRImageView.image = SQRCode.createQR('The fragrant rain is as crisp as a bead, but the family is not aware of it but nothing. One heart is only for others, who is the green makeup for?', iconImageName: '123') } }

例3

// // detectorViewController.swift // QRCode // // Created by HMC on 16/8/12. // Copyright © 2016 SKing. All rights reserved. // import UIKit class detectorViewController: UIViewController { @IBOutlet weak var imageView: UIImageView! override func viewDidLoad() { super.viewDidLoad() // get image guard let image = imageView.image else{ return } let returnStr = SQRCode.detectorQRFromImage(image) //alert shows the recognized content Let alert = UIAlertController(title: 'recognize content', message:returnStr, preferredStyle: .Alert) Let action = UIAlertAction(title: 'close', style: .Default, handler: { (action : UIAlertAction) in self.dismissViewControllerAnimated(true, completion: nil) }) alert.addAction(action) presentViewController(alert, animated: true, completion: nil) } }