#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. 《C程序设计语言》练习 1-8,1-9

    #include <stdio.h> /*编写一个统计空格,制表符与换行符个数的程序*/ main() { int a,b,c,d;//a表示空格个数,b表示制表符个数,c表示换行符个数 ...

  2. 5)添加分发参数c,选择控制器

    目录关系:  代码展示: newnewnew.controller.class.php <?php /** * Created by PhpStorm. * User: Interact * D ...

  3. OpenCV Canny 边缘检测

    #include "opencv2/imgproc/imgproc.hpp" #include "opencv2/highgui/highgui.hpp" #i ...

  4. SHELL小练习

    1.SHELL编程服务器IP修改脚本 脚本实现动态IP修改: 脚本实现静态IP修改: 实现IP地址输入判断正确性: IP地址修改成功判断&回滚: 2.SHELL编程Tomcat多实例管理脚本( ...

  5. Jmeter之CSV文件读取

    注意execl表生成的CSV文件的文件编码是GB2312和分隔符就好了

  6. Android开发之《Module相互引用,NDK不能正常Debug》

    解决Android Studio不能进入调试模式问题 Android Studio 2.2.3 native debug 无法调试?:https://www.zhihu.com/question/54 ...

  7. [USACO5.1] Musical Themes

    后缀数组求最长重复且不重叠子串. poj 1743 传送门 洛谷 P2743 传送门 1.子串可以“变调”(即1 3 6和3 5 8视作相同).解决办法:求字符串相邻元素的差形成新串.用新字符串求解最 ...

  8. Python---11模块

    在计算机程序的开发过程中,随着程序代码越写越多,在一个文件里代码就会越来越长,越来越不容易维护. 为了编写可维护的代码,我们把很多函数分组,分别放到不同的文件里,这样,每个文件包含的代码就相对较少,很 ...

  9. TICA 2019 自动的自动化测试——智能化一站式的API测试服务

    阿里QA导读:新奥集团中台的陈磊为我们打开了AI测试驱动的视野,同时也深入浅出地介绍了如何打造智能化API测试框架.通过陈磊老师的分享,我们看到了AI-DT的无限可能性.以后,AI能不能代替大部分手动 ...

  10. Catalan母函数法解表达式