假设你不知道ZBarSDK怎么用,请下载demo

http://download.csdn.net/detail/u013686641/7858917

假设你已经配置好ZBarSDK 。那么以下这个类能够直接用

以下是效果图

//

//  头文件

//  TestProject

//

#import <UIKit/UIKit.h>

#import "ZBarSDK.h"

@interface yxpQrCode :UIViewController

@end

//

//  实现文件

//  TestProject

//

#import "yxpQrCode.h"

#define SCANVIEW_EdgeTop
40.0

#define SCANVIEW_EdgeLeft
50.0

#define TINTCOLOR_ALPHA
0.2  //浅色透明度

#define DARKCOLOR_ALPHA
0.5  //深色透明度

@interfaceyxpQrCode ()<ZBarReaderViewDelegate>

{

UIView *_QrCodeline;

NSTimer *_timer;

//设置扫描画面

UIView *_scanView;

ZBarReaderView *_readerView;

}

@end

@implementation yxpQrCode

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle
*)nibBundleOrNil

{

self = [superinitWithNibName:nibNameOrNil
bundle:nibBundleOrNil];

if (self) {

// Custom initialization

}

returnself;

}

- (void)viewDidLoad

{

[superviewDidLoad];

self.title=@"扫描二维码";

//初始化扫描界面

[selfsetScanView];

_readerView= [[ZBarReaderViewalloc]init];

,
VIEW_WIDTH);

_readerView.tracksSymbols=NO;

_readerView.readerDelegate =self;

[_readerViewaddSubview:_scanView];

//关闭闪光灯

;

[self.viewaddSubview:_readerView];

//扫描区域

//readerView.scanCrop =

[_readerViewstart];

[selfcreateTimer];

}

#pragma mark -- ZBarReaderViewDelegate

-(void)readerView:(ZBarReaderView *)readerView didReadSymbols:(ZBarSymbolSet
*)symbols fromImage:(UIImage *)image

{

constzbar_symbol_t *symbol =zbar_symbol_set_first_symbol(symbols.zbarSymbolSet);

NSString *symbolStr = [NSStringstringWithUTF8String:
zbar_symbol_get_data(symbol)];

//推断是否包括 头'http:'

NSString *regex =@"http+:[^\\s]*";

NSPredicate *predicate = [NSPredicatepredicateWithFormat:@"SELF
MATCHES %@",regex];

UIAlertView *alertView=[[UIAlertViewalloc]
initWithTitle:@""message:symbolStr
delegate:nilcancelButtonTitle:@"取消"otherButtonTitles:nil];

[alertViewshow];

//推断是否包括 头'ssid:'

NSString *ssid =@"ssid+:[^\\s]*";;

NSPredicate *ssidPre = [NSPredicatepredicateWithFormat:@"SELF
MATCHES %@",ssid];

if ([predicate
evaluateWithObject:symbolStr]) {

}

else
if([ssidPreevaluateWithObject:symbolStr]){

NSArray *arr = [symbolStr
componentsSeparatedByString:@";"];

]componentsSeparatedByString:@":"];

]componentsSeparatedByString:@":"];

symbolStr = [NSStringstringWithFormat:@"ssid:
%@ \n password:%@",

[arrInfoHead],[arrInfoFoot]];

UIPasteboard *pasteboard=[UIPasteboardgeneralPasteboard];

//然后,能够使用例如以下代码来把一个字符串放置到剪贴板上:

pasteboard.];

}

}

//二维码的扫描区域

- (void)setScanView

{

_scanView=[[UIViewalloc]
initWithFrame,
)];

_scanView.backgroundColor=[UIColorclearColor];

//最上部view

UIView* upView = [[UIViewalloc]
,,
VIEW_WIDTH,SCANVIEW_EdgeTop)];

upView.alpha =TINTCOLOR_ALPHA;

upView.backgroundColor = [UIColorblackColor];

[_scanViewaddSubview:upView];

//左側的view

UIView *leftView = [[UIViewalloc]
,SCANVIEW_EdgeTop,
SCANVIEW_EdgeLeft*SCANVIEW_EdgeLeft)];

leftView.alpha =TINTCOLOR_ALPHA;

leftView.backgroundColor = [UIColorblackColor];

[_scanViewaddSubview:leftView];

/******************中间扫描区域****************************/

UIImageView *scanCropView=[[UIImageViewalloc]
initWithFrame:CGRectMake(SCANVIEW_EdgeLeft,SCANVIEW_EdgeTop,
VIEW_WIDTH*SCANVIEW_EdgeLeft)];

//scanCropView.image=[UIImage imageNamed:@""];

scanCropView.layer.borderColor=[UIColorgetThemeColor].CGColor;

scanCropView.layer.borderWidth=2.0;

scanCropView.backgroundColor=[UIColorclearColor];

[_scanViewaddSubview:scanCropView];

//右側的view

UIView *rightView = [[UIViewalloc]
initWithFrame:CGRectMake(VIEW_WIDTH-SCANVIEW_EdgeLeft,SCANVIEW_EdgeTop,
SCANVIEW_EdgeLeft*SCANVIEW_EdgeLeft)];

rightView.alpha =TINTCOLOR_ALPHA;

rightView.backgroundColor = [UIColorblackColor];

[_scanViewaddSubview:rightView];

//底部view

UIView *downView = [[UIViewalloc]
*SCANVIEW_EdgeLeft+SCANVIEW_EdgeTop,VIEW_WIDTH,
VIEW_HEIGHT)];

//downView.alpha = TINTCOLOR_ALPHA;

downView.backgroundColor = [[UIColorblackColor]
colorWithAlphaComponent:TINTCOLOR_ALPHA];

[_scanViewaddSubview:downView];

//用于说明的label

UILabel *labIntroudction= [[UILabelalloc]
init];

labIntroudction.backgroundColor = [UIColorclearColor];

labIntroudction.,,
);

labIntroudction.;

labIntroudction.font=[UIFontsystemFontOfSize:15.0];

labIntroudction.textAlignment=NSTextAlignmentCenter;

labIntroudction.textColor=[UIColorwhiteColor];

labIntroudction.text=@"将二维码对准方框,就可以自己主动扫描";

[downViewaddSubview:labIntroudction];

UIView *darkView = [[UIViewalloc]
, downView.frame.size.height-100.0,VIEW_WIDTH,
100.0)];

darkView.backgroundColor = [[UIColorblackColor] 
colorWithAlphaComponent:DARKCOLOR_ALPHA];

[downViewaddSubview:darkView];

//用于开关灯操作的button

UIButton *openButton=[[UIButtonalloc]
,,
300.0, 40.0)];

[openButtonsetTitle:@"开启闪光灯" forState:UIControlStateNormal];

[openButton setTitleColor:[UIColorwhiteColor]
forState:UIControlStateNormal];

openButton.titleLabel.textAlignment=NSTextAlignmentCenter;

openButton.backgroundColor=[UIColorgetThemeColor];

openButton.titleLabel.font=[UIFontsystemFontOfSize:22.0];

[openButton addTarget:selfaction:@selector(openLight)forControlEvents:UIControlEventTouchUpInside];

[darkViewaddSubview:openButton];

//画中间的基准线

_QrCodeline = [[UIViewalloc]
initWithFrame:CGRectMake(SCANVIEW_EdgeLeft,SCANVIEW_EdgeTop,
VIEW_WIDTH)];

_QrCodeline.backgroundColor = [UIColorgetThemeColor];

[_scanViewaddSubview:_QrCodeline];

}

- (void)openLight

{

)
{

;

}else

{

;

}

}

- (void)viewWillDisappear:(BOOL)animated

{

[superviewWillDisappear:animated];

)
{

;

}

[selfstopTimer];

[_readerViewstop];

}

//二维码的横线移动

- (void)moveUpAndDownLine

{

CGFloat Y=_QrCodeline.frame.origin.y;

//CGRectMake(SCANVIEW_EdgeLeft, SCANVIEW_EdgeTop, VIEW_WIDTH-2*SCANVIEW_EdgeLeft, 1)]

*SCANVIEW_EdgeLeft+SCANVIEW_EdgeTop==Y){

[UIView beginAnimations:@"asa" context:nil];

[UIView setAnimationDuration:];

_QrCodeline.frame=CGRectMake(SCANVIEW_EdgeLeft, SCANVIEW_EdgeTop, VIEW_WIDTH-*SCANVIEW_EdgeLeft,);

[UIView commitAnimations];

}elseif(SCANVIEW_EdgeTop==Y){

[UIView beginAnimations:@"asa" context:nil];

[UIView setAnimationDuration:];

_QrCodeline.frame=CGRectMake(SCANVIEW_EdgeLeft, VIEW_WIDTH-*SCANVIEW_EdgeLeft+SCANVIEW_EdgeTop, VIEW_WIDTH-*SCANVIEW_EdgeLeft,);

[UIView commitAnimations];

}

}

- (void)createTimer

{

//创建一个时间计数

_timer=[NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:@selector(moveUpAndDownLine)
userInfo:nil repeats:YES];

}

- (void)stopTimer

{

if ([_timer isValid] ==
YES) {

[_timer invalidate];

_timer =nil;

}

}

- (void)didReceiveMemoryWarning

{

[super didReceiveMemoryWarning];

// Dispose of any resources that can be recreated.

}

@end


二维码框架ZBarSDK的使用和自己定义二维码扫描界面方法的更多相关文章

  1. 用c#开发微信(2)扫描二维码,用户授权后获取用户基本信息 (源码下载)

    本文将介绍基于Senparc.Weixin微信开发框架来实现网页授权来获取用户基本信息.先生成包含授权及回调url信息的二维码:用户用微信扫描之后,被要求授权以获取Ta的用户基本信息:用户授权后,通过 ...

  2. ios二维码扫描插件,适配当前主流扫描软件,自定义扫描界面。

            二维码介绍: 二维码(QR(Quick Response)code),又称二维条码,最早起源于日本. 它是用特定的几何图形按一定规律在平面(二维方向)上分布的黑白相间的图形,是所有信息 ...

  3. Atitit 常用二维码对比(QR、PDF417、DM、汉信码 Aztec code maxicode

    Atitit 常用二维码对比(QR.PDF417.DM.汉信码 Aztec code maxicode DM码则更"小",可在仅仅25mm²的面积上编码30个数字.但也就是因为太小 ...

  4. IOS开发小功能2:二维码扫描界面的设计(横线上下移动)

    效果图如上,实现的是一个二维码扫描界面. 下面我贴出线条上下移动的代码,至于二维码的代码是用的第三方库. 首先是整体的结构: 注意下面的库文件一个都不能少,否则会报错. TLTiltHighlight ...

  5. java二维码生成-谷歌(Google.zxing)开源二维码生成学习及实例

    java二维码生成-谷歌(Google.zxing)开源二维码生成的实例及介绍   我们使用比特矩阵(位矩阵)的QR码编码在缓冲图片上画出二维码 实例有以下一个传入参数 OutputStream ou ...

  6. QRCode二维码生成方案及其在带LOGO型二维码中的应用(1)

    原文:QRCode二维码生成方案及其在带LOGO型二维码中的应用(1) 提要:很多公司为商业宣传之需,常将企业LOGO加入二维码中,但如果LOGO遮挡区域足够地大,二维码就变得无法识别.那么,有没有一 ...

  7. QRCode二维码生成方案及其在带LOGO型二维码中的应用(2)

    原文:QRCode二维码生成方案及其在带LOGO型二维码中的应用(2) 续前:QRCode二维码生成方案及其在带LOGO型二维码中的应用(1)  http://blog.csdn.net/johnsu ...

  8. 使用Jquery+EasyUI 进行框架项目开发案例讲解之四 组织机构管理源码分享

    http://www.cnblogs.com/huyong/p/3404647.html 在上三篇文章  <使用Jquery+EasyUI进行框架项目开发案例讲解之一---员工管理源码分享> ...

  9. 使用Jquery+EasyUI 进行框架项目开发案例讲解之三---角色管理源码分享

    使用Jquery+EasyUI 进行框架项目开发案例讲解之三 角色管理源码分享    在上两篇文章  <使用Jquery+EasyUI进行框架项目开发案例讲解之一---员工管理源码分享> ...

随机推荐

  1. ES6重点知识点总结(2)

    ES6重点知识点总结(2) call和apply的作用是什么?区别是什么? call和apply的功能基本相同,都是实现继承或者转换对象指针的作用: 唯一不通的是前者参数是罗列出来的,后者是存到数组中 ...

  2. CSS3特效——六面体

    <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...

  3. 【hihocoder 1519】 逃离迷宫II

    [题目链接]:http://hihocoder.com/problemset/problem/1519?sid=1098756 [题意] Chinese [题解] bfs题; 根据bfs的性质; 第一 ...

  4. UVALIVE 4256 Salesmen

    Salesmen Time Limit: 3000ms Memory Limit: 131072KB This problem will be judged on UVALive. Original ...

  5. WinServer-IIS-IIS负载均衡

    安装应用程序路由 提供的服务器的地址必须是可以访问,不然无法进入到下面的这个管理界面 来自为知笔记(Wiz)

  6. [ReactVR] Add Shapes Using 3D Primitives in React VR

    React VR ships with a handful of 3D primitives. We'll importprimitives like <Sphere/>, <Box ...

  7. [TS] Class Properties Public, Private and Read Only Modifiers

    In the constructor, we want to set the prop to readonly, you need to do like this: class Superhero { ...

  8. word2vec词向量训练及中文文本类似度计算

    本文是讲述怎样使用word2vec的基础教程.文章比較基础,希望对你有所帮助! 官网C语言下载地址:http://word2vec.googlecode.com/svn/trunk/ 官网Python ...

  9. Google翻译PDF文档

    Google翻译PDF文档 翻译软件虽多如牛毛,但有关整段/全文翻译,堪用的软件极少, 涉及专业技术的文献.胜任翻译工作的人力稀缺.少不了project师讴心沥血. 由于多是PDF格式.即使要翻译个概 ...

  10. php抽奖、随机广告算法

    我们先完毕后台PHP的流程,PHP的主要工作是负责配置奖项及相应的中奖概率,当前端页面点击翻动某个方块时会想后台PHP发送ajax请求,那么后台PHP依据配置的概率,通过概率算法给出中奖结果,同一时候 ...