首页 > 其他 > 详细

二维码

时间:2016-01-25 22:56:46      阅读:516      评论:0      收藏:0      [点我收藏+]

生成二维码

前提:需要导入以下代码

技术分享

 

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];

 

二维码

原文:http://www.cnblogs.com/YhhMzl/p/5158882.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!