iOS 二维码扫描
// 导入 AVFoundation.framwork 框架
#import "HDCodeViewController.h"
#import "HDNormalViewController.h"
#import <AVFoundation/AVFoundation.h> @interface HDCodeViewController ()<AVCaptureMetadataOutputObjectsDelegate>
@property(strong,nonatomic)UIView *codeView;
@property(strong,nonatomic)UIImageView *myLine;
@end @implementation HDCodeViewController
{
AVCaptureSession *_session;
NSString *_theString;
NSTimer *_timer;
BOOL _upOrdown;
NSInteger _num;
} - (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
[self initUI];
[self prepareCamara];
[self initData];
} -(void)dealloc
{
[_timer invalidate];
_timer = nil; _session = nil;
} -(void)initData
{
_num = ;
} #pragma mark - UI Stuff Methods
-(void)initUI
{
self.codeView = [[UIView alloc]initWithFrame:CGRectMake(, , SCREEN_WIDTH, SCREEN_HEIGHT - )];
self.codeView.backgroundColor = [UIColor clearColor];
[self.view addSubview:self.codeView]; UIImageView *imageView = [[UIImageView alloc]initWithFrame:CGRectMake((SCREEN_WIDTH-)/, , , )];
imageView.image = [UIImage imageNamed:@"code_square"];
[self.codeView addSubview:imageView]; self.myLine = [[UIImageView alloc] initWithFrame:CGRectMake((SCREEN_WIDTH-)/, , , )];
self.myLine.contentMode = UIViewContentModeScaleToFill;
self.myLine.image = [UIImage imageNamed:@"code_movingBar"];
[self.codeView addSubview:self.myLine]; _timer = [NSTimer scheduledTimerWithTimeInterval:. target:self selector:@selector(moveLine) userInfo:nil repeats:YES];
} -(void)moveLine
{
CGFloat height = self.myLine.frame.origin.y;
CGFloat width = self.myLine.frame.size.width; if (_upOrdown == NO) {
_num ++;
self.myLine.frame = CGRectMake((SCREEN_WIDTH-)/, height+, width, );
if (*_num == ) {
_upOrdown = YES;
}
}
else {
_num --;
self.myLine.frame = CGRectMake((SCREEN_WIDTH-)/, height-, width, );
if (_num == ) {
_upOrdown = NO;
}
}
} #pragma Camara Stuff Methods
-(void)prepareCamara
{
AVCaptureDevice *device = [AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeVideo];
AVCaptureDeviceInput *input = [AVCaptureDeviceInput deviceInputWithDevice:device error:nil];
AVCaptureMetadataOutput *output = [[AVCaptureMetadataOutput alloc]init];
[output setMetadataObjectsDelegate:self queue:dispatch_get_main_queue()]; _session = [[AVCaptureSession alloc]init];
[_session setSessionPreset:AVCaptureSessionPresetHigh]; [_session addInput:input];
[_session addOutput:output];
output.metadataObjectTypes = @[AVMetadataObjectTypeQRCode,AVMetadataObjectTypeEAN13Code, AVMetadataObjectTypeEAN8Code, AVMetadataObjectTypeCode128Code]; AVCaptureVideoPreviewLayer *layer = [AVCaptureVideoPreviewLayer layerWithSession:_session];
layer.videoGravity = AVLayerVideoGravityResizeAspectFill;
layer.frame = CGRectMake((SCREEN_WIDTH-)/, , , );
[self.codeView.layer insertSublayer:layer atIndex:]; [_session startRunning];
} -(void)captureOutput:(AVCaptureOutput *)captureOutput didOutputMetadataObjects:(NSArray *)metadataObjects fromConnection:(AVCaptureConnection *)connection{
if (metadataObjects.count>) {
//[session stopRunning];
AVMetadataMachineReadableCodeObject * metadataObject = [metadataObjects objectAtIndex : ];
_theString = metadataObject.stringValue;
NSLog(@"%@",_theString);//扫出来的字符串
}
} @end
iOS 二维码扫描的更多相关文章
- Ios二维码扫描(系统自带的二维码扫描)
Ios二维码扫描 这里给大家介绍的时如何使用系统自带的二维码扫描方法和一些简单的动画! 操作步骤: 1).首先你需要搭建UI界面如图:下图我用了俩个imageview和一个label 2).你需要在你 ...
- iOS二维码扫描IOS7系统实现
扫描相关类 二维码扫描需要获取摄像头并读取照片信息,因此我们需要导入系统的AVFoundation框架,创建视频会话.我们需要用到一下几个类: AVCaptureSession 会话对象.此类作为硬件 ...
- iOS - 二维码扫描和应用跳转
序言 前面我们已经调到过怎么制作二维码,在我们能够生成二维码之后,如何对二维码进行扫描呢? 在iOS7之前,大部分应用中使用的二维码扫描是第三方的扫描框架,例如ZXing或者ZBar.使用时集成麻烦, ...
- ios二维码扫描插件,适配当前主流扫描软件,自定义扫描界面。
二维码介绍: 二维码(QR(Quick Response)code),又称二维条码,最早起源于日本. 它是用特定的几何图形按一定规律在平面(二维方向)上分布的黑白相间的图形,是所有信息 ...
- iOS二维码扫描的实现(Swift)
随着二维码的普遍使用,二维码扫描也成为了很多app的一个基本功能,本篇主要来介绍一下如何实现一个简单的二维码扫描功能.本文使用了XCode自带的AVFoundation 库,利用Swfit语言实现. ...
- iOS 二维码扫描 通过ZBar ZXing等第三方库
扫描二维码的开源库有很多如 ZBar.ZXing等 ZBar的使用方法: 下载ZBar SDK 地址https://github.com/bmorton/ZBarSDK ZBarSDK是一个开源的SD ...
- ios二维码扫描
1.添加AVFoundation.framework框架 2,控制器中实现 //第一步添加AVFoundation.framework框架 #import "ViewController.h ...
- 有关iOS系统中调用相机设备实现二维码扫描功能的注意点(3/3)
今天我们接着聊聊iOS系统实现二维码扫描的其他注意点. 大家还记得前面我们用到的输出数据的类对象吗?AVCaptureMetadataOutput,就是它!如果我们需要实现目前主流APP扫描二维码的功 ...
- iOS开发-二维码扫描和应用跳转
iOS开发-二维码扫描和应用跳转 序言 前面我们已经调到过怎么制作二维码,在我们能够生成二维码之后,如何对二维码进行扫描呢? 在iOS7之前,大部分应用中使用的二维码扫描是第三方的扫描框架,例如Z ...
随机推荐
- 关于xcode导出设置中的一些概念
Development Certificates:在电脑通过秘钥串生成一个私人秘钥,这就是:CertificateSigningRequest.certSigningRequest 简称CSR,团队中 ...
- 深入理解定时器系列第二篇——被誉为神器的requestAnimationFrame
× 目录 [1]引入 [2]特点 [3]使用[4]兼容[5]应用 前面的话 与setTimeout和setInterval不同,requestAnimationFrame不需要设置时间间隔.这有什么好 ...
- codeforces C. Vanya and Scales
C. Vanya and Scales Vanya has a scales for weighing loads and weights of masses w0, w1, w2, ..., w10 ...
- EntityFramework之数据库以及表基本创建(一)
前言 之前有学过EF一段时间那时EF才4.0似乎还不太稳定,而现在EF都已7.0版本,同时AspNet Identity都与此大有关联,看来是大势所趋于是开始学习EF,在学EF过程中也遇到一些小问题, ...
- 窥探Swift编程之强大的Switch
之前初识Swift中的Switch语句时,真的是让人眼前一亮,Swift中Switch语句有好多特有而且特好用的功能.说到Switch, 只要是写过程序的小伙伴对Switch并不陌生.其在程序中的出镜 ...
- 如何用Python实现杨辉三角和心
1. 如何实现杨辉三角 import copy list=[] newlist=[] def Fibonacci(list,n): newlist.append(0) if n ==1: return ...
- MyCAT日志分析
MyCAT日志对于了解MyCAT的运行信息不可获取,譬如MyCAT是否采用读写分离,对于一个查询语句,MyCAT是怎样执行的,每个分片会分发到哪个节点上等等. 默认是info级别,通过log4j.xm ...
- Perl碎碎念
1. 如何去重 #!/usr/bin/perl use strict; my %hash; while(<>){ chomp; print "$_\n" unless ...
- 好玩的SQL
1. 做一个3*3的加法表 SQL), (); A||'+'||B||'='||(A+B) ------------------------------------------------------ ...
- 你所不知道的15个Axure使用技巧
你有用原型开发工具吗?如果有,那你用的是Axure还是别的? 从以前就喜欢使用Axure,主要是觉得它能清楚的表达设计的思路,还有交互的真实再现,能让看的人一目了然,昨天看了这篇博文,便更加确定Axu ...