iOS 7 二维码
//
// TCTosweepScan.m
// TongChengSearch
//
// Created by Fighting on 14-6-11.
// Copyright (c) 2014年 tcsos.com. All rights reserved.
//
#import "TCTosweepScan.h"
#import <AVFoundation/AVFoundation.h>
@interface TCTosweepScan()<AVCaptureMetadataOutputObjectsDelegate>
@property (strong, nonatomic)AVCaptureDevice *device;
@property (strong, nonatomic)AVCaptureDeviceInput *input;
@property (strong, nonatomic)AVCaptureMetadataOutput *output;
@property (strong, nonatomic)AVCaptureSession *session;
@property (strong, nonatomic)AVCaptureVideoPreviewLayer *preview;
@end
@implementation TCTosweepScan
- (instancetype)initConfigWith:(CGRect)frame previewFrame:(CGRect)previewFrame {
if (self = [super init]) {
self.frame = frame;
self.autoresizingMask = YES;
//初始化UI
[self initUI:previewFrame];
}
return self;
}
- (void)dealloc {
// 1. 如果扫描完成,停止会话
[session stopRunning];
// 2. 删除预览图层
[preview removeFromSuperlayer];
[output setMetadataObjectsDelegate:nil queue:nil];
}
//初始化UI
- (void)initUI:(CGRect)previewFrame {
// Device
device = [AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeVideo];
NSError *error = nil;
// Input
input = [AVCaptureDeviceInput deviceInputWithDevice:device error:&error];
if (error) {
NSLog(@"你手机不支持二维码扫描!");
return;
}
// Output
output = [[AVCaptureMetadataOutput alloc] init];
[output setMetadataObjectsDelegate:self queue:dispatch_get_main_queue()];
// Session
session = [[AVCaptureSession alloc] init];
[session setSessionPreset:AVCaptureSessionPresetHigh];
if ([session canAddInput:input]) {
[session addInput:input];
}
if ([session canAddOutput:output]) {
[session addOutput:output];
}
// 条码类型
output.metadataObjectTypes = @[AVMetadataObjectTypeQRCode];
// Preview
preview = [AVCaptureVideoPreviewLayer layerWithSession:session];
preview.videoGravity = AVLayerVideoGravityResizeAspectFill;
preview.frame = previewFrame;
[self.layer addSublayer:preview];
}
//启动扫描
- (void)startScan {
// Start
[session startRunning];
}
// 此方法是在识别到QRCode,并且完成转换
// 如果QRCode的内容越大,转换需要的时间就越长
- (void)captureOutput:(AVCaptureOutput *)captureOutput didOutputMetadataObjects:(NSArray *)metadataObjects fromConnection:(AVCaptureConnection *)connection {
// 1. 如果扫描完成,停止会话
[session stopRunning];
// 2. 删除预览图层
[preview removeFromSuperlayer];
NSString *val = nil;
if (metadataObjects.count > 0) {
AVMetadataMachineReadableCodeObject *obj = metadataObjects[0];
val = obj.stringValue;
}
if (delegate && [delegate respondsToSelector:@selector(TCTosweepScanDidEnd:)]) {
[delegate TCTosweepScanDidEnd:val];
}
}
@synthesize delegate;
@synthesize device;
@synthesize input;
@synthesize output;
@synthesize session;
@synthesize preview;
iOS 7 二维码的更多相关文章
- iOS开发-二维码扫描和应用跳转
iOS开发-二维码扫描和应用跳转 序言 前面我们已经调到过怎么制作二维码,在我们能够生成二维码之后,如何对二维码进行扫描呢? 在iOS7之前,大部分应用中使用的二维码扫描是第三方的扫描框架,例如Z ...
- iOS 原生二维码扫描和生成
代码地址如下:http://www.demodashi.com/demo/12551.html 一.效果预览: 功能描述:WSLNativeScanTool是在利用原生API的条件下封装的二维码扫描工 ...
- iOS - QRCode 二维码
1.QRCode 在 iOS7 以前,在 iOS 中实现二维码和条形码扫描,我们所知的有,两大开源组件 ZBar 与 ZXing. 这两大组件我们都有用过,这里总结下各自的缺点: 1.ZBar 在扫描 ...
- IOS开发 二维码功能的实现
原帖地址:http://yul100887.blog.163.com/blog/static/20033613520121020611299/ 如今二维码随处可见,无论是实物商品还是各种礼券都少不了二 ...
- AJ学IOS 之二维码学习,快速打开相机读取二维码
AJ分享,必须精品 上一篇文章写了怎么生成二维码,这儿就说说怎么读取吧,反正也很简单,iOS封装的太强大了 步骤呢就是这样: 读取二维码需要导入AVFoundation框架#import <AV ...
- AJ学IOS 之二维码学习,快速生成二维码
AJ分享,必须精品 二维码是一项项目中可能会用到的,iOS打开相机索取二维码的速度可不是Android能比的...(Android扫描二维码要来回来回晃...) 简单不多说,如何把一段资料(网址呀,字 ...
- iOS 生成二维码
首先先下载生成二维码的支持文件 libqrencode 添加依赖库 CoreGraphics.framework. QuartzCore.framework.AVFoundation.framewor ...
- iOS开发 二维码生成
基于libqrencode的二维码生成 + (void)drawQRCode:(QRcode *)code context:(CGContextRef)ctx size:(CGFloat)size { ...
- iOS开发-二维码的基本使用
二维码在生活中出现的频率越来越多了,大街小巷各个角落,它的出现更大的作用是代替功能单一的传统条形码,但是通常很多人第一次见到这个都不清楚这是干嘛用的.最初第一次见到可能就是买到的商品上有一个数字的条形 ...
随机推荐
- win7 snmp
http://blog.chinaunix.net/uid-21857285-id-3340206.html
- 创建.NET应用程序所经历的步骤
1.使用某种.NET兼容语言(如C#)编写应用程序.2.把代码编译为(CIL),存储在程序集中.3.在执行代码时(如果这是一个可执行文件,就自动运行,或者在其他代码使用它时运行),首先必须使用JIT( ...
- uva 714 Copying Books(二分法求最大值最小化)
题目连接:714 - Copying Books 题目大意:将一个个数为n的序列分割成m份,要求这m份中的每份中值(该份中的元素和)最大值最小, 输出切割方式,有多种情况输出使得越前面越小的情况. 解 ...
- git中的常用指令名及其意义
add 添加新文件到 Git 代码仓库的索引中 $ git add filename mv 移动或重命名文件 $ git mv old-filename new-filename rm 从工作目录和 ...
- 【转】[教程]隐藏ActionBar中的MenuItem
原文网址:http://blog.csdn.net/appte/article/details/12104823 有时候我们需要在不同的时候改变ActionBar中MenuItem的项数,或者隐藏某些 ...
- Angular.js VS. Ember.js:谁将成为Web开发的新宠?
这篇博文陈述的非常好,比较全面的剖析了Angular.js与Ember.js,下面的链接,供学习与参考: http://www.csdn.net/article/2013-09-09/2816880- ...
- 高性能Java解析器实现过程详解
如果你没有指定数据或语言标准的或开源的Java解析器, 可能经常要用Java实现你自己的数据或语言解析器.或者,可能有很多解析器可选,但是要么太慢,要么太耗内存,或者没有你需要的特定功能.或者开源解析 ...
- hadoop2.2.0伪分布模式64位安装
hadoop2.2.0伪分布模式64位安装用到的软件:jdk-6u45-linux-x64.bin,hadoop-2.2.0.x86_64.tar.gz 修改主机名vim /etc/sysconfig ...
- ORA-00314,redolog 损坏,或丢失处理方法
alertsid.log报错信息: Fri Sep 27 15:18:39 2013 Started redo scan Fri Sep 27 15:18:39 2013 Errors in file ...
- 关于Spring配置 (Cannot find class [org.apache.commons.dbcp.BasicDataSource] 问题)
myeclipse抛出异常 org.springframework.beans.factory.CannotLoadBeanClassException: Cannot find /webapps/t ...