#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. git的命令操作指南

    Git图形化界面我用的还可以,但是命令就不太会了,索性和大家一起学习下Git命令的用法...一般来说,日常使用只要记住下图6个命令,就可以了.但是熟练使用,恐怕要记住60-100个命令. fetch ...

  2. 第19届亚太零售商大会 | 奇点云CEO行在受邀出席发表演讲

    2019年9月5日—7日,第19届亚太零售商大会在重庆举行. 亚太零售商大会作为世界三大零售盛会之一,是亚太地区零售行业最具规模.最具影响力的零售行业盛会.本次大会以“新零售·新消费·新动力·合作与共 ...

  3. [LC] 203. Remove Linked List Elements

    Remove all elements from a linked list of integers that have value val. Example: Input: 1->2-> ...

  4. 【Linux_Shell 脚本编程学习笔记六、shell的数值运算】

    1.bc 命令的用法(可以整数也可以小数): bc是 UNIX下的计算器,它也可以用在命令行下面: 例: 给自变量 i 加 1 [root@docker Demo_test]# i= [root@do ...

  5. delicate|definite|density|deny doing|draw up |draw on|no equal for|establish|equipped|

    ADJ-GRADED 技巧性很强的;注重细节的A delicate task, movement, action, or product needs or shows great skill and ...

  6. gin源码剖析

    介绍 Gin 是一个 Golang 写的 web 框架,具有高性能的优点,基于 httprouter,它提供了类似martini但更好性能(路由性能约快40倍)的API服务.官方地址:https:// ...

  7. [Redis] Redis哨兵模式部署 - zz胖的博客

    1. 部署Redis集群 redis的安装及配置参考[redis部署] 本文以创建一主二从的集群为例. 1.1 部署与配置 先创建sentinel目录,在该目录下创建8000,8001,8002三个以 ...

  8. [洛谷P4549] [模板] 裴蜀定理

    18.10.03模拟赛T1. 出题人xcj(Mr.Handsome)十分良心,给了一道送分题...... 互测题好久没有出现送分题了.xcj真棒. 题目传送门 幸亏之前看过,否则真的是送分题都拿不到. ...

  9. Maven基本概念和操作

    最近在学Java,找来一个开源项目练手,它是用 Spring Boot 搭建的框架,于是去学 Spring Boot,然而 Spring Boot 需要有 Spring 框架和 Maven 的使用经验 ...

  10. Starting php-fpm [18-Jun-2019 12:56:59] NOTICE: PHP message: PHP Warning: Version warning提示报错解决

    php-fpm在命令行重启时出现如下提示信息在终端上,虽然不影响使用,但是不够干净利落,参考了一篇国外博客得以解决,参考链接:https://community.centminmod.com/thre ...