http://vdisk.weibo.com/s/Gbaa1
我们来看看。h文件:
# import & lt; UIKit/UIKit.h> #进口“ZBarSDK.h” @ interface ViewController: UIViewController@ property(强,原子)UIImageView * qRImageView; @ property(强,原子)ZBarReaderViewController *读者; @ property(强,原子)NSString * qRUrl; ——(IBAction) QRPress: (id)发送者; ——(IBAction) qrBtnPress: (id)发送者; @end
- (void) { (超级viewDidLoad);//做任何额外的设置加载视图后,通常从笔尖。 自我。qRUrl=[[NSString alloc] init);//从这以下到32行 自我。读者=[[ZBarReaderViewController alloc] init); self.reader。readerDelegate=自我; self.reader。supportedOrientationsMask=ZBarOrientationMaskAll; ZBarImageScanner *扫描仪=self.reader.scanner; 【扫描仪setSymbology: ZBAR_I25 配置:ZBAR_CFG_ENABLE :0);//这部分为zBarSDK文档提供的例子给出的主要的意思就是初始化ZBarReaderViewController类的对象,以及设置代理回调方法为- (void) p_w_picpathPickerController: (UIImagePickerController *)读者//didFinishPickingMediaWithInfo:(NSDictionary *)信息 自我。qRImageView=[[UIImageView alloc] initWithFrame: CGRectMake (0, 0, 320, 400)]; (自我。视图addSubview self.qRImageView):; }
//制作二维码 ——(IBAction) qrBtnPress:发送者(id) {/*字符转二维码 导入libqrencode文件 引入头文件# QRCodeGenerator进口”。h”即可使用 */self.qRImageView。p_w_picpath=[QRCodeGenerator qrImageForString: @”asd户外“p_w_picpathSize: self.qRImageView.bounds.size.width); }
//点击按钮时将扫描二维码需要的照相机视图,即self.reader (ZBarReaderViewController)类的对象 ——(IBAction) QRPress:发送者(id) { 【自我presentViewController:自我。读者动画:是的完成:^ { NSLog (@“fd”); }); }
//这个回调方法的写法是固定,只要知道以下几点就好需要的数据是从symbol.data中取出的,因此也就需要在. h文件中声明一个字符串接受就好。在这里我在. h中声明了self.qRUrl对象进行接受,之后只要按下面的格式写就好。 - (void) p_w_picpathPickerController: (UIImagePickerController *)读者 didFinishPickingMediaWithInfo:(NSDictionary *)信息 { id结果=[信息objectForKey: ZBarReaderControllerResults]; ZBarSymbol *符号=零; (符号的结果) { NSLog(@“符号=% @”symbol.data); 打破; } 自我。qRUrl=symbol.data; UIAlertView *警报=[[UIAlertView alloc] initWithTitle:自我。qRUrl信息:自我。qRUrl委托:自我cancelButtonTitle: @“OK”otherButtonTitles: nil); (警报显示); self.qRImageView。p_w_picpath=[信息objectForKey: UIImagePickerControllerOriginalImage]; (自我。读者dismissViewControllerAnimated:是的完成:^ { }); }