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. (22)odoo 安装旧模块报错处理

    一些老版本的模块没有得到升级,所以经常碰到模块无法安装的问题. No module name osv 将模块的 from osv import osv,fields 改为 from openerp.o ...

  2. 简述 Ruby 与 DSL 在 iOS 开发中的运用

    阅读本文不需要预先掌握 Ruby 与 DSL 相关的知识 何为 DSL DSL(Domain Specific Language) 翻译成中文就是:"领域特定语言".首先,从定义就 ...

  3. 用Google Analytics跟踪JavaScript Errors (译)

    通过custom events来实施 // Track basic JavaScript errors window.addEventListener('error', function(e) { _ ...

  4. Java DES 加解密文件

    import com.mchange.v2.io.DirectoryDescentUtils; import javax.crypto.Cipher;import javax.crypto.Ciphe ...

  5. HDU 5768 中国剩余定理

    题目链接:Lucky7 题意:求在l和r范围内,满足能被7整除,而且不满足任意一组,x mod p[i] = a[i]的数的个数. 思路:容斥定理+中国剩余定理+快速乘法. (奇+ 偶-) #incl ...

  6. php和AJAX用户注册演示程序

    <! doctype html public "-//w3c//dtd html 4.0//en" "http://www.w3.org/tr/rec-html14 ...

  7. mysql 远程连接速度慢的解决方案

    PHP远程连接MYSQL速度慢,有时远程连接到MYSQL用时4-20秒不等,本地连接MYSQL正常,出现这种问题的主要原因是,默认安装的MYSQL开启了DNS的反向解析,在MY.INI(WINDOWS ...

  8. js获取浏览器的版本代码

    <script>function GetXmlHttpObject(){var xmlHttp=null;var httptype='';try { // Firefox, Opera 8 ...

  9. Kafka简要图解

    LinkedIn贡献的分布式消息系统 - 请参考这里 kafka集群:producer写入消息,consumer读取消息 消息分为不同主题,每个主题可以分为多个partition(并行),每个part ...

  10. S1:对象与JSON

    JSON全称为JavaScript对象表示法(JavaScript Object Notation). JSON是JavaScript中对象的字面量,是对象的表示方法,通过使用JSON,可以减少中间变 ...