ZXingObjC二维码扫描
#import "QRScanViewController.h"
#import "AppDelegate.h" @interface QRScanViewController ()
{
BOOL infoShowing;
UIAlertView *alert;
BOOL upToDown;
int num;
UIImageView *lineImageView;
NSTimer *timer;
}
@end @implementation QRScanViewController
@synthesize capture;
@synthesize scanRectView;
@synthesize backImageView;
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
[self initViewFrame];
}
return self;
} - (void)viewDidLoad
{
[super viewDidLoad]; self.capture = [[ZXCapture alloc] init];
self.capture.camera = self.capture.back;
self.capture.focusMode = AVCaptureFocusModeContinuousAutoFocus;
self.capture.rotation = 90.0f;
self.capture.layer.frame = self.view.bounds; [self.view.layer addSublayer:self.capture.layer];
[self.view bringSubviewToFront:self.backImageView];
[self.view bringSubviewToFront:self.scanRectView]; lineImageView = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"scan_line.png"]];
lineImageView.frame = CGRectMake(self.scanRectView.frame.origin.x, self.scanRectView.frame.origin.y, self.scanRectView.frame.size.width, );
[self.view addSubview:lineImageView];
} - (void)lineAnimation
{
if (!([self isViewLoaded] && [self.view superview])) {
return;
}
if (upToDown) {
num++;
float temp = 0.0;
if (*num > self.scanRectView.frame.size.height-) {
temp = self.scanRectView.frame.size.height+self.scanRectView.frame.origin.y;
upToDown = NO;
}else{
temp = self.scanRectView.frame.origin.y + *num;
}
lineImageView.frame = CGRectMake(self.scanRectView.frame.origin.x, temp, self.scanRectView.frame.size.width, );
}else{
num--;
float temp = 0.0;
if (num <= ) {
temp = self.scanRectView.frame.origin.y;
upToDown = YES;
}else{
temp = self.scanRectView.frame.origin.y + *num;
}
lineImageView.frame = CGRectMake(self.scanRectView.frame.origin.x, temp, self.scanRectView.frame.size.width, );
}
} - (void)viewDidAppear:(BOOL)animated
{
if (timer) {
[timer invalidate];
timer = nil;
}
upToDown = YES;
num = ;
lineImageView.frame = CGRectMake(self.scanRectView.frame.origin.x, self.scanRectView.frame.origin.y, self.scanRectView.frame.size.width, );
timer = [NSTimer scheduledTimerWithTimeInterval:0.02 target:self selector:@selector(lineAnimation) userInfo:nil repeats:YES];
} - (void)stopTimer
{
if (timer) {
[timer invalidate];
timer = nil;
}
} - (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated]; self.capture.delegate = self;
self.capture.layer.frame = self.view.bounds;
// CGAffineTransform captureSizeTransform = CGAffineTransformMakeScale(320 / self.view.frame.size.width, 480 / self.view.frame.size.height);
// self.capture.scanRect = CGRectApplyAffineTransform(self.scanRectView.frame, captureSizeTransform);
if (viewer.device == DEVICE_IPAD || viewer.device == DEVICE_IPAD3) {
[self showaCapture];
}else{
self.capture.rotation = 90.0f;
CGAffineTransform transform = CGAffineTransformMakeRotation();
[self.capture setTransform:transform];
CGRect f = CGRectMake(, , self.view.bounds.size.width, self.view.bounds.size.height);
self.view.layer.frame=f;
self.capture.layer.frame = f;
}
} - (void)showaCapture
{
CGAffineTransform transform;
if (self.interfaceOrientation == UIInterfaceOrientationLandscapeLeft)
{
self.capture.rotation = 180.0f;
transform = CGAffineTransformMakeRotation(M_PI/);
}
else if (self.interfaceOrientation == UIInterfaceOrientationLandscapeRight)
{
self.capture.rotation = 0.0f;
transform = CGAffineTransformMakeRotation(-M_PI/);
}
else if (self.interfaceOrientation == UIInterfaceOrientationPortrait)
{
self.capture.rotation = 90.0f;
transform = CGAffineTransformMakeRotation();
}
else if (self.interfaceOrientation == UIInterfaceOrientationPortraitUpsideDown)
{
self.capture.rotation = 270.0f;
transform = CGAffineTransformMakeRotation(M_PI);
} [self.capture setTransform:transform];
CGRect f = CGRectMake(, , self.view.bounds.size.width, self.view.bounds.size.height);
self.view.layer.frame=f;
self.capture.layer.frame = f;
} #pragma mark - ZXCaptureDelegate Methods //- (void)captureCameraIsReady:(ZXCapture *)capture
//{
//
//}
//
//- (void)captureSize:(ZXCapture *)capture width:(NSNumber *)width height:(NSNumber *)height
//{
//
//} - (void)captureResult:(ZXCapture *)capture result:(ZXResult *)result
{
if (!result) {
return;
}
NSLog(@"结果是什么= %@",result.text);
NSString *formatString = [self barcodeFormatToString:result.barcodeFormat];
if (![formatString isEqualToString:@"QR Code"]) {
return;
} NSString *display = [NSString stringWithFormat:@"Scanned!\n\nFormat: %@\n\nContents:\n%@", formatString, result.text];
NSLog(@"二维码是%@",display);
// [decodedLabel performSelectorOnMainThread:@selector(setText:) withObject:display waitUntilDone:YES];
AudioServicesPlaySystemSound(kSystemSoundID_Vibrate);
if (infoShowing) {
return;
}
if (alert) {
[alert release];
alert = nil;
}
alert = [[UIAlertView alloc] initWithTitle:@"信息" message:result.text delegate:nil cancelButtonTitle:@"Cancel" otherButtonTitles:@"OK", nil];
alert.delegate = self;
[alert show];
infoShowing = YES;
} #pragma mark - Private Methods - (NSString *)barcodeFormatToString:(ZXBarcodeFormat)format {
switch (format) {
case kBarcodeFormatAztec:
return @"Aztec"; case kBarcodeFormatCodabar:
return @"CODABAR"; case kBarcodeFormatCode39:
return @"Code 39"; case kBarcodeFormatCode93:
return @"Code 93"; case kBarcodeFormatCode128:
return @"Code 128"; case kBarcodeFormatDataMatrix:
return @"Data Matrix"; case kBarcodeFormatEan8:
return @"EAN-8"; case kBarcodeFormatEan13:
return @"EAN-13"; case kBarcodeFormatITF:
return @"ITF"; case kBarcodeFormatPDF417:
return @"PDF417"; case kBarcodeFormatQRCode:
return @"QR Code"; case kBarcodeFormatRSS14:
return @"RSS 14"; case kBarcodeFormatRSSExpanded:
return @"RSS Expanded"; case kBarcodeFormatUPCA:
return @"UPCA"; case kBarcodeFormatUPCE:
return @"UPCE"; case kBarcodeFormatUPCEANExtension:
return @"UPC/EAN extension"; default:
return @"Unknown";
}
} //- (BOOL)shouldAutorotate
//{
// return YES;
//}
//
//- (BOOL)shouldAutomaticallyForwardRotationMethods
//{
// return YES;
//}
//
//- (NSUInteger)supportedInterfaceOrientations
//{
// return UIInterfaceOrientationMaskAll;
//} - (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
} - (void)rotated
{
[self setViewFrame];
} - (void)setViewFrame{
} - (void)initViewFrame{
} #pragma mark - UIAlertViewDelegate
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
if (buttonIndex != alert.cancelButtonIndex) { }
infoShowing = NO;
} - (void)dealloc
{
[super dealloc];
}
/*
#pragma mark - Navigation @end
ZXingObjC二维码扫描的更多相关文章
- iOS学习——iOS原生实现二维码扫描
最近项目上需要开发扫描二维码进行签到的功能,主要用于开会签到的场景,所以为了避免作弊,我们再开发时只采用直接扫描的方式,并且要屏蔽从相册读取图片,此外还在二维码扫描成功签到时后台会自动上传用户的当前地 ...
- XAMARIN ANDROID 二维码扫描示例
现在二维码的应用越来越普及,二维码扫描也成为手机应用程序的必备功能了.本文将基于 Xamarin.Android 平台使用 ZXing.Net.Mobile 做一个简单的 Android 条码扫描示 ...
- [Unity3D]自制UnityForAndroid二维码扫描插件
一周左右终于将二维码生成和扫描功能给实现了,终于能舒缓一口气了,从一开始的疑惑为啥不同的扫码客户端为啥扫出来的效果不同?通用的扫描器扫出来就是一个下载APK,自制的扫描器扫出来是想要的有效信息,然后分 ...
- 有关iOS系统中调用相机设备实现二维码扫描功能的注意点(3/3)
今天我们接着聊聊iOS系统实现二维码扫描的其他注意点. 大家还记得前面我们用到的输出数据的类对象吗?AVCaptureMetadataOutput,就是它!如果我们需要实现目前主流APP扫描二维码的功 ...
- Android仿微信二维码扫描
转载:http://blog.csdn.net/xiaanming/article/details/10163203 了解二维码这个东西还是从微信中,当时微信推出二维码扫描功能,自己感觉挺新颖的,从一 ...
- Android—ZXing二维码扫描遇到的问题
最近工作中需要开发带有二维码扫描功能的软件(基于开源项目ZXing),遇到的问题记录一下,也希望给大家带来帮助. 1.首先因为扫描要开摄像机所以加权限是一定的,不然后面什么都不能进行 <uses ...
- Ios二维码扫描(系统自带的二维码扫描)
Ios二维码扫描 这里给大家介绍的时如何使用系统自带的二维码扫描方法和一些简单的动画! 操作步骤: 1).首先你需要搭建UI界面如图:下图我用了俩个imageview和一个label 2).你需要在你 ...
- iOS 自带二维码扫描功能的实现
自从iOS7以后中新增了二维码扫描功能.因此可以在不借助第三方类库的情况下简单的写出二维码的扫描功能: 原生的二维码扫描功能在AVFoundation框架下,所以在使用原生的二维码扫描功能时要先导入A ...
- PhoneGap(二维码扫描 )
关于 phoneGap 如何做 二维码扫描 1. 先配置好, 环境 http://coenraets.org/blog/cordova-phonegap-3-tutorial/http: ...
随机推荐
- EMCCD
EMCCD 即电子倍增CCD,是探测领域内灵敏度极高的一种高端光电探测产品. 在光子探测领域的应用发展对探测器灵敏度的要求不断提高,EMCCD (Electron-Multiplying CCD)技术 ...
- 推荐几款开源的js日期控件
做为一个正规的网站,经常需要一些日期或时间的筛选,所以我们今天就推荐二十多款javascript的js日期/时间筛选插件.个个经典,绝对有你需要的. My97DatePicker ,国人开发的一款js ...
- mysqli存储过程
<?php$link = mysqli_connect('localhost','root','','chinatupai'); $sql = "call getEmail('000 ...
- Jquery中$(document).ready() 和 JavaScript中的window.onload方法 比较
Jquery中$(document).ready()的作用类似于传统JavaScript中的window.onload方法,不过与window.onload方法还是有区别的. 1.执行时间 win ...
- Java POI导出Excel不弹框选择下载路径(下载文件不选择下载路径,默认) Chrome
在Chrome浏览器中,Java导出Excel文件时,浏览器弹出提示框,需要选择下载路径 在Chrome中的高级设置中,把“下载前询问每个文件的保存位置”去掉就解决了 DEEPLOVE(LC)
- 如何快速找出Linux中的重复文件
md5sum | sort | uniq -w32 --all-repeated=separate [1]find -not -empty -type f -printf “%s\n” :find是查 ...
- jsde与gulp使用说明
jade是一款基于haml的html模板引擎,已改为pug 1.全局安装 npm install jade -g 新建一个jade文件夹,再建一个后缀名为.jade的文件编辑.jade文件 jade ...
- Android APP性能及专项测试(个人整理)
移动测试. Android测试 .APP测试 Android篇 1. 性能测试 Android性能测试分为两类:1.一类为rom版本(系统)的性能测试2.一类为应用app的性能测试 Android ...
- Jetson TX2镜像刷板法
使用Nvidia官方自带的脚本,备份镜像.恢复镜像,快速在新板子中部署DL环境 在之前的一篇博客中,详细介绍了使用JetPack刷系统以及使用离线包部署DL环境(cuda.cudnn.opencv.c ...
- LISTAGG函数
官网进入 该函数作用是可以实现对列值得拼接: 根据官网介绍,可以对列值排序进行拼接,也可以分组拼接 1.1运行结果 1.2运行结果 2运行结果 注意该函数提供的 over( partition by ...