1,生成二维码
BarReaderView *readview = [ZBarReaderView new]; // 初始化
readview.frame= CGRectMake(0, 0, 320, 460); // 改变frame
readview.readerDelegate= self; // 设置delegate
readview.allowsPinchZoom= NO; // 不使用Pinch手势变焦
readerView.torchMode = 0; //关闭闪光灯
CGRectscanMaskRect = CGRectMake(60, CGRectGetMidY(readerView.frame) - 126, 200, 200);
readerView.scanCrop = [self getScanCrop:scanMaskRectreaderViewBounds:self.readerView.bounds];//设置扫描区域
[self.viewaddSubview:readview];
[readview start];//启动扫描
- (void)readerView:(ZBarReaderView *)readerViewdidReadSymbols:(ZBarSymbolSet *)symbols fromImage:(UIImage *)image
{
for (ZBarSymbol *symbol in symbols) {
NSLog(@"%@", symbol.data);
break;
}
[self.readerView stop];
}
NSString *symbolStr = sym.data;
if ([symbolStrcanBeConvertedToEncoding:NSShiftJISStringEncoding])
{
symbolStr = [NSStringstringWithCString:[symbolStrcStringUsingEncoding: NSShiftJISStringEncoding] encoding:NSUTF8StringEncoding];
}