zoukankan      html  css  js  c++  java
  • 二维码

    生成二维码

    前提:需要导入以下代码

    1.在ViewController的.m文件中定义一个UIImageView属性, 存放二维码

    @property (weak, nonatomic) IBOutlet UIImageView *imageView;

    2.在viewDidLoad方法中写以下代码即可

    self.imageView.image = [QRCodeGenerator qrImageForString:@"欢欢"imageSize:self.imageView.frame.size.width];

    二维码扫描:在真机上才可以

    前提:需要引入系统框架

    #import <AVFoundation/AVFoundation.h>

    1.定义属性

    @property(nonatomic, strong)AVCaptureSession *captureSession;

    2.在viewDidLoad中写以下代码

    self.captureSession = [[AVCaptureSession alloc] init];

        //自定义相机界面

        AVCaptureDevice *device = [AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeAudio];

        AVCaptureDeviceInput *input = [AVCaptureDeviceInput deviceInputWithDevice:device error:nil];

        //设置session的输入流

        [_captureSession addInput:input];

        //设置session的输出流

        AVCaptureMetadataOutput *outPut = [[AVCaptureMetadataOutput alloc] init];

        //为输出流设置代理

        [outPut setMetadataObjectsDelegate:self queue:dispatch_get_main_queue()];

        //设置扫码类型

        [_captureSession addOutput:outPut];

        //二维码和人脸

        [outPut setMetadataObjectTypes:@[AVMetadataObjectTypeQRCode, AVMetadataObjectTypeFace]];

        //生成相机涂层

        AVCaptureVideoPreviewLayer *layer = [AVCaptureVideoPreviewLayer layerWithSession:self.captureSession];

        layer.frame = self.view.bounds;

        [self.view.layer addSublayer:layer];

        //开始扫描

        [self.captureSession startRunning];

  • 相关阅读:
    androidlayout_weight的使用
    软件开发中的真理.
    apk,task,android:process与android:sharedUserId的区别
    WIFI连接
    go simple web server
    echo命令
    shell if
    linux grep命令(包括正则)
    make命令和Makefile文件
    linux中grep命令的用法
  • 原文地址:https://www.cnblogs.com/YhhMzl/p/5158882.html
Copyright © 2011-2022 走看看