#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. arduino驱动oled

    OLED一款小巧的显示屏,感觉可以做出很可爱的东西. 这次实验的这款是128X64的OLED屏幕 , 芯片是SSD1306,请确认自家模块芯片型号,不然对不上号啊 使用IIC的方法,简单实验显示示例程 ...

  2. Navicat 12 无限期试用

    最近发现navicat12又过期了,以前的是用的破解软件,然后是到1899年过期哈哈哈哈哈哈.重装了系统后,软件也重装了,发现破解软件不好使了,就先试用了,现在到期了.很是难受,这可咋整,不过在网上看 ...

  3. 在服务器搭建git服务器

    服务端操作 安装Git及创建用户组.用户 123 yum install gitgroupadd gitadduser git -g git 禁止用户git登录 修改/etc/passwd文件: 找到 ...

  4. The Tower(ccpc吉林)

    http://acm.hdu.edu.cn/contests/contest_showproblem.php?pid=1005&cid=867 #include<iostream> ...

  5. RS232串口通信详解

    串口是计算机上一种非常通用的设备通信协议. ---------------------------------串口的引脚定义: 9芯 信号方向来自 缩写 描述 1 调制解调器 CD 载波检测 2 调制 ...

  6. 前端-css-长期维护

    ###############    CSS简介    ################ # CSS # HTML是骨架 # CSS是样式 # JS是动作 # css和html是分成两个文件编写的,这 ...

  7. 错误修改.bashrc文件导致所有命令无法使用解决方法

    export PATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/bin

  8. [LC] 303. Range Sum Query - Immutable

    Given an integer array nums, find the sum of the elements between indices i and j (i ≤ j), inclusive ...

  9. MOOC(1)-使用pycharm新建Django项目、开发post接口

    https://www.cnblogs.com/liqu/p/9308966.html 1.安装Django的两种方式: > 1) pip install django 2)下载离线安装包,进入 ...

  10. Vimmer一套全语言支持的完美Vim配置——附Monaco字体

    本配置轻量,强大,支持流行语言,包括现代前段框架react,jsx,vue,pug(jade)高亮和格式化,支持各种语言的自动补全.同时新增了MonacoNerd字体,可以显示文件类型logo,Mon ...