ZXingObjc 使用初探究
@interface ViewController () <ZXCaptureDelegate>
@property (nonatomic,strong) UIImageView *centerView;
@property (nonatomic,strong) ZXCapture *capture;
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
self.centerView=[[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 200, 200)];
[self.centerView setImage:[UIImage imageNamed:@"qrScanZone"]];
self.=[UIColor colorWithRed:0.5 green:0.5 blue:0.5 alpha:0.1];
self.=self.;
[self.view addSubview:self.centerView];
self.capture = [[ZXCapture alloc] init];
self. = self.;
self. = AVCaptureFocusModeContinuousAutoFocus;
self. = 90.0f;
self. = self.;
[self. addSublayer:self.];
[self.view bringSubviewToFront:self.centerView];
}
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
self. = self;
self. = self.;
CGAffineTransform captureSizeTransform = CGAffineTransformMakeScale(320 / self., 480 / self.);
self. = CGRectApplyAffineTransform(self., captureSizeTransform);
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation {
return toInterfaceOrientation == UIInterfaceOrientationPortrait;
}
- (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";
}
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (void)captureResult:(ZXCapture *)capture result:(ZXResult *)result {
if (!result){
return;
}
NSString *formatString = [self barcodeFormatToString:];
NSLog(@"%@",[NSString stringWithFormat:@"条码格式:%@ \n内容:%@", formatString, ]);
[self.capture stop];
//震动提示
AudioServicesPlaySystemSound(kSystemSoundID_Vibrate);
}
@end