1.首先使用Cocoapods导入库 ZBarSDK

2.敲代码:

ViewController.h

//
// ViewController.h
// erweima
//
// Created by shaoting on 15/12/16.
// Copyright © 2015年 9elephas. All rights reserved.
// #import <UIKit/UIKit.h>
#import "ZBarSDK.h"
@interface ViewController : UIViewController<ZBarReaderDelegate> @end

ViewController.m

//
// ViewController.m
// erweima
//
// Created by shaoting on 15/12/16.
// Copyright © 2015年 9elephas. All rights reserved.
// #import "ViewController.h"
#define ScreenFrame [[UIScreen mainScreen]bounds]
@interface ViewController () @end @implementation ViewController - (void)viewDidLoad {
[super viewDidLoad];
UIButton * btn = [UIButton buttonWithType:UIButtonTypeCustom];
btn.frame = CGRectMake(0, 0, 50, 50);
[btn setTitle:@"扫描" forState:UIControlStateNormal];
btn.backgroundColor = [UIColor redColor];
[btn addTarget:self action:@selector(erweima:) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:btn];
// Do any additional setup after loading the view, typically from a nib.
}
-(void)erweima:(UIButton *)btn{
ZBarReaderViewController * reader = [ZBarReaderViewController new];//初始化相机控制器
reader.readerDelegate = self;
reader.supportedOrientationsMask = ZBarOrientationMaskAll;//基本适配
reader.showsHelpOnFail = YES;
reader.scanCrop = CGRectMake(0, 0, 1, 1);
ZBarImageScanner * scanner = reader.scanner;
[scanner setSymbology:25 config:0 to:0];
UIView * view = [[UIView alloc]initWithFrame:CGRectMake(0, 0, ScreenFrame.size.width, ScreenFrame.size.height)];
reader.cameraOverlayView = view;
[self presentViewController:reader animated:YES completion:^{ }]; }
- (void) imagePickerController: (UIImagePickerController*) reader
didFinishPickingMediaWithInfo: (NSDictionary*) info{
id<NSFastEnumeration> results =
[info objectForKey: ZBarReaderControllerResults];
ZBarSymbol *symbol = nil;
for(symbol in results)
break;
UIAlertView * alert = [[UIAlertView alloc]initWithTitle:@"消息" message:symbol.data delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:@"OK1", nil];
[alert show]; }
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
} @end

demo下载:http://download.csdn.net/detail/shaoting19910730/9426472

使用真机测试:

iOS ZBarSDK的基本使用:扫描的更多相关文章

  1. iOS开发-二维码扫描和应用跳转

    iOS开发-二维码扫描和应用跳转   序言 前面我们已经调到过怎么制作二维码,在我们能够生成二维码之后,如何对二维码进行扫描呢? 在iOS7之前,大部分应用中使用的二维码扫描是第三方的扫描框架,例如Z ...

  2. 使用OClint进行iOS项目的静态代码扫描

    使用OClint进行iOS项目的静态代码扫描 原文链接:http://blog.yourtion.com/static-code-analysis-ios-using-oclint.html 最近需要 ...

  3. iOS 原生二维码扫描和生成

    代码地址如下:http://www.demodashi.com/demo/12551.html 一.效果预览: 功能描述:WSLNativeScanTool是在利用原生API的条件下封装的二维码扫描工 ...

  4. IOS 使用 ZbarSDK 二维码扫描

    1. 下载SDK   https://github.com/bmorton/ZBarSDK 2. 引用到项目中 3. 添加引用 4. AppDelegate中添加下面代码 5. 在需要使用扫描的con ...

  5. iOS 系统二维码扫描(可限制扫描区域)

    使用 AVFoundation系统库来进行二维码扫描并且限制扫描二维码的范围.(因为默认的是全屏扫描) -(void)beginCode { //1.摄像头设备 AVCaptureDevice *de ...

  6. iOS 原生二维码扫描(可限制扫描区域)

    篇文章的主要原因不是展示如何使用  AVFoundation 来进行二维码扫描,更主要的是限制扫描二维码的范围.(因为默认的是全屏扫描) 项目遇到扫描二维码的功能需求,这里我放弃了使用三方库,而采用了 ...

  7. 【转】 iOS 原生二维码扫描(可限制扫描区域)

    在用 AVFoundation 完成扫码后,遇到2个问题: 1,如何限制扫描范围? 2.条形码如何扫描? 一位朋友的文章帮助了我,特地转来,可以帮到有需要的朋友. 原文:http://blog.csd ...

  8. iOS 原生二维码扫描,带扫描框和扫描过程动画

    在代码中使用了相对布局框架Masonry 准备两张图片,一张是扫描边框,一张是扫描时的细线分别命名 scanFrame.png和scanLine.png并提前放入工程 导入相对布局头文件 #defin ...

  9. 扫描二维码判断移动设备(Android/ios),以及判断是否微信端扫描

    <section class="download"> <a href="apk地址" class="android" st ...

随机推荐

  1. hdu---1506(Largest Rectangle in a Histogram/dp最大子矩阵)

    Largest Rectangle in a Histogram Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 ...

  2. 超实用的JavaScript代码段 --倒计时效果

    现今团购网.电商网.门户网等,常使用时间记录重要的时刻,如时间显示.倒计时差.限时抢购等,本文分析不同倒计时效果的计算思路及方法,掌握日期对象Date,获取时间的方法,计算时差的方法,实现不同的倒时计 ...

  3. 《JavaScript权威指南》读书笔记(三)

    日期:2015-12-05 浏览器location和history: replace不会显示历史,location会: history对象脚本不能真正访问,但支持三种方法:back().foward( ...

  4. sql 语句 截取字符串的两种方案

    方案一:使用内置的函数 SUBSTRING,CHARINDEX,LEN三个内置函数 理论: SUBSTRING语法   SUBSTRING ( value_expression , start_exp ...

  5. php-fpm的重启/关闭

    php 5.3.3 下的php-fpm 不再支持 php-fpm 以前具有的 /usr/local/php/sbin/php-fpm (start|stop|reload)等命令,需要使用信号控制: ...

  6. JDE处理选项

    处理选项为JDE的一种数据结构,命名方式如下: The name of a data structure can be a maximum of characters-only if you begi ...

  7. 学习记录008-crond和visudo

    1.每隔两个小时将/etc/servers文件打包备份到.tmp下(每次名字不同) [root@kaka cc.log]# tar zcvf /server/backup/ccc.log_$(date ...

  8. 10款优秀Vim插件帮你打造完美IDE

    导读 如果你稍微写过一点代码,就能知道“集成开发环境”(IDE)是多么的便利.不管是Java.C还是Python,当IDE会帮你检查语法.后台编译,或者自动导入你需要的库时,写代码就变得容易许多.另外 ...

  9. CSS最常用和实用的技巧

    1.重置浏览器的字体大小重置浏览器的默认值 ,然后重设浏览器的字体大小你可以使用雅虎的用户界面重置的CSS方案 ,如果你不想下载9MB的文件,代码如下: body,div,dl,dt,dd,ul,ol ...

  10. winform插入sql的事务处理

    实现目的:点击按钮,原子性执行两条sql语句,同时成功或同时失败 数据库有这三个字段(忽略已有的一条记录): 一.用事务的sql语句 按钮事件完整代码: //事务处理插入sql语句 using (SQ ...