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. Merge k Sorted Lists [LeetCode]

    Merge k sorted linked lists and return it as one sorted list. Analyze and describe its complexity. S ...

  2. jdk 安装

    安装JDK 选择安装目录 安装过程中会出现两次 安装提示 .第一次是安装 jdk ,第二次是安装 jre .建议两个都安装在同一个java文件夹中的不同文件夹中.(不能都安装在java文件夹的根目录下 ...

  3. 模拟器的tableView的分割线不显示

    只有iOS9和iPhone6 plus模拟器上TableView分割线不会显示. 原因: 由于iPhone6 plus的分辨率较高,开发的时候同常都使用command + 3 或者 command + ...

  4. OUT函数及其熟练使用,split的用法

    using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.T ...

  5. Objective-C:Foundation框架-常用类-NSMutableArray

    NSMutableArray是NSArray对的子类,它是可变的,可以随意添加或者删除元素.与Array,也有静态和动态两种创建方法.也可已使用NSArray的方法来创建NSMutableArray. ...

  6. TokuDB介绍——本质是分形树(一个叶子4MB)+缓存减少写操作

    其性能特点见:http://www.cnblogs.com/billyxp/p/3567421.html TokuDB 是一个高性能.支持事务处理的 MySQL 和 MariaDB 的存储引擎.Tok ...

  7. Oracle 中的 decode

    含义解释:decode(条件,值1,返回值1,值2,返回值2,...值n,返回值n,缺省值) 该函数的含义如下:IF 条件=值1 THEN RETURN(翻译值1)ELSIF 条件=值2 THEN R ...

  8. Octopus系列之接下来的任务

    更新默认国家[已实现] 更新每页显示条数的后台控制[已实现] 更新国家和区域的Ajax的关联[已实现] 更新详情页面的 属性选择 脚本提示[已实现 可以做到和兰亭一样的效果了] 增加优惠方案的设置和批 ...

  9. ASP.NET伪静态 UrlRewrite(Url重写) 实现和配置

    核心提示:大家一定经常在网络上看到很多网站的地址后缀都是用XX.HTML或者XX.ASPX等类似静态文件的标示来操作的吧,那么大家有怀疑过他真的是一个一个的静态生成的文件么,静态文件的生成的优缺有好有 ...

  10. 转: CSS中float和clear的理解

    float:浮动,比如,默认的,我们知道,div是占满一行的,现在我们想把两个div显示在一行上,那怎么办呢<div style="width:100px;">1111 ...