#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二维码扫描的更多相关文章

  1. iOS学习——iOS原生实现二维码扫描

    最近项目上需要开发扫描二维码进行签到的功能,主要用于开会签到的场景,所以为了避免作弊,我们再开发时只采用直接扫描的方式,并且要屏蔽从相册读取图片,此外还在二维码扫描成功签到时后台会自动上传用户的当前地 ...

  2. XAMARIN ANDROID 二维码扫描示例

    现在二维码的应用越来越普及,二维码扫描也成为手机应用程序的必备功能了.本文将基于 Xamarin.Android 平台使用 ZXing.Net.Mobile  做一个简单的 Android 条码扫描示 ...

  3. [Unity3D]自制UnityForAndroid二维码扫描插件

    一周左右终于将二维码生成和扫描功能给实现了,终于能舒缓一口气了,从一开始的疑惑为啥不同的扫码客户端为啥扫出来的效果不同?通用的扫描器扫出来就是一个下载APK,自制的扫描器扫出来是想要的有效信息,然后分 ...

  4. 有关iOS系统中调用相机设备实现二维码扫描功能的注意点(3/3)

    今天我们接着聊聊iOS系统实现二维码扫描的其他注意点. 大家还记得前面我们用到的输出数据的类对象吗?AVCaptureMetadataOutput,就是它!如果我们需要实现目前主流APP扫描二维码的功 ...

  5. Android仿微信二维码扫描

    转载:http://blog.csdn.net/xiaanming/article/details/10163203 了解二维码这个东西还是从微信中,当时微信推出二维码扫描功能,自己感觉挺新颖的,从一 ...

  6. Android—ZXing二维码扫描遇到的问题

    最近工作中需要开发带有二维码扫描功能的软件(基于开源项目ZXing),遇到的问题记录一下,也希望给大家带来帮助. 1.首先因为扫描要开摄像机所以加权限是一定的,不然后面什么都不能进行 <uses ...

  7. Ios二维码扫描(系统自带的二维码扫描)

    Ios二维码扫描 这里给大家介绍的时如何使用系统自带的二维码扫描方法和一些简单的动画! 操作步骤: 1).首先你需要搭建UI界面如图:下图我用了俩个imageview和一个label 2).你需要在你 ...

  8. iOS 自带二维码扫描功能的实现

    自从iOS7以后中新增了二维码扫描功能.因此可以在不借助第三方类库的情况下简单的写出二维码的扫描功能: 原生的二维码扫描功能在AVFoundation框架下,所以在使用原生的二维码扫描功能时要先导入A ...

  9. PhoneGap(二维码扫描 )

    关于 phoneGap 如何做 二维码扫描 1.        先配置好, 环境 http://coenraets.org/blog/cordova-phonegap-3-tutorial/http: ...

随机推荐

  1. TCP、UDP、HTTP与HTTPS

    TCP.UDP.HTTP与HTTPS都是通信协议,在这里首先先介绍一下什么是通信协议. 什么是通信协议? 通信协议(communications protocol)是指双方实体完成通信或服务所必须遵循 ...

  2. 104)PHP,目录树状输出

    使用特定数量的缩进达到树状目的! 核心问题,计算需要缩进的数量! 缩进级别,与递归调用深度保持一致.每当执行一级递归操作,所找到的文件的缩进级别+; 语法实现: 增加一个参数,表示当前函数调用的深度级 ...

  3. Struts配置文件以Spring的方式实现自定义加载

    在使用struts时,我们需要在web.xml中配置过滤器,同时我们需要配置struts的配置文件路径来加载项目中struts的相关配置信息.如果我们不配置路径的话,Struts会有一些默认的加载路径 ...

  4. C#输入输出及类型转换,变量,常量。

    //输出 Console.WriteLine("大哇塞"); 自动回车的. Console.Write("Hello world");  不带回车的 注意: 1 ...

  5. deeplearning.ai 改善深层神经网络 week2 优化算法

    这一周的主题是优化算法. 1.  Mini-batch: 上一门课讨论的向量化的目的是去掉for循环加速优化计算,X = [x(1) x(2) x(3) ... x(m)],X的每一个列向量x(i)是 ...

  6. 【AUTO Uninstaller - 使用教程】Autodesk系列软件终极完美修复卸载工具【转载】

    小伙伴是不是遇到 CAD/3dmax/maya/Revit/Inventor 安装失败或者安装不了的问题了呢?AUTODESK系列软件着实令人头疼,CAD/3dmax/maya/Revit/Inven ...

  7. Nginx笔记总结十七:nginx生成缩略图配置(http_image_filter_module)

    编译: ./configure --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_realip_module-- ...

  8. [CF1009F] Dominant Indices (+dsu on tree详解)

    这道题用到了dsu(Disjoint Set Union) on tree,树上启发式合并. 先看了CF的官方英文题解,又看了看zwz大佬的题解,差不多理解了dsu on tree的算法. 但是时间复 ...

  9. Python---13靠谱的Pycharm安装详细教程

    昨天自学廖雪峰老师的python课程时,用的sublime编辑器,在命令行模式进行的输出,输出结果一直报错,说Python版本有问题,但在版本是满足要求的.最后在同事的电脑上运行了一下,是可以正常输出 ...

  10. Tozan and Gezan(x*y<a*b)

    E - Tozan and Gezan Time limit : 2sec / Memory limit : 256MB Score : 700 points Problem Statement Yo ...