标签:
导入必要的框架
实现ZBarReaderDelegate协议
//二维码识别 -(void)sysbutbuttonclick{ //初始化相机控制器 ZBarReaderViewController *reader = [ZBarReaderViewController new]; //设置代理 reader.readerDelegate = self; //基本适配 reader.supportedOrientationsMask = ZBarOrientationMaskAll; //二维码/条形码识别设置 ZBarImageScanner *scanner = reader.scanner; [scanner setSymbology: ZBAR_I25 config: ZBAR_CFG_ENABLE to: 0]; //弹出系统照相机,全屏拍摄 [self presentViewController:reader animated:YES completion:nil]; } - (void) imagePickerController: (UIImagePickerController*) reader didFinishPickingMediaWithInfo: (NSDictionary*) info { NSLog(@"info=%@",info); // 得到条形码结果 id<NSFastEnumeration> results =[info objectForKey: ZBarReaderControllerResults]; ZBarSymbol *symbol = nil; for(symbol in results) // EXAMPLE: just grab the first barcode break; NSLog(@"%@",symbol.data); }
实现ZBarReaderViewDelegate协议
//二维码识别 -(void)sysbutbuttonclick{ //初始化照相机窗口 ZBarReaderView *readview = [ZBarReaderView new]; //自定义大小 readview.frame = myScreen; //自定义添加相关指示.........发挥各自的APP的想象力 //此处省略美化10000行代码................... //……………………….. // 好进入正题—— 接着设置好代理 readview.readerDelegate = self; //将其照相机拍摄视图添加到要显示的视图上 [self.view addSubview:readview]; //二维码/条形码识别设置 ZBarImageScanner *scanner = readview.scanner; [scanner setSymbology: ZBAR_I25 config: ZBAR_CFG_ENABLE to: 0]; //启动,必须启动后,手机摄影头拍摄的即时图像菜可以显示在readview上 [readview start]; } -(void)readerView:(ZBarReaderView *)readerView didReadSymbols:(ZBarSymbolSet *)symbols fromImage:(UIImage *)image { ZBarSymbol *symbol = nil; for (symbol in symbols) { break; } NSLog(@"========%@==========",symbol.data); }
标签:
原文地址:http://my.oschina.net/u/2346786/blog/518279