在整合zxing for iPhone的同时pipe理视图

我正在尝试将zxing集成到我现有的iPhone应用程序中。 我已经提到了项目下载中包含的ScanTest示例,并成功地构build并运行了扫描程序。

我的问题在于pipe理项目的意见,以合并扫描仪。 目前我有一个已经存在的视图控制器(VC-A),它需要扫描仪的能力。 我创build了一个新的视图控制器(VC-B)来启动ZXingWidgetController扫描仪视图。 所以stream程如下所示:

VC-A-> presentModalViewController(VC-B) – > VC-B-> presentModalViewController(ZXingWidgetController)

现在和ScanTest示例应用程序一样,当扫描完成时,将从VC-B调用dissmissModalViewController,closuresZXingWidgetController的视图。 问题出在我尝试的方式,我无法解雇VC-B回到VC-A。 扫描完成/取消时,我创build了一组委托方法来通知VC-A。 我使用这些方法获得扫描数据,但无法驳回VC-B的观点。

我不想修改已经存在的视图控制器VC-A,因此我无法直接将ZXingWidgetController合并到VC-B中,因此需要将VC-A放在一个.mm文件中。

编辑:现在我干掉ZXingWidgetController的模式,完全。 在VC-B的viewDidLoad使用这个代码

 //Create custom overlay OverlayView *scannerView = [[OverlayView alloc]initWithFrame:CGRectMake(27, 107, 267, 253) cancelEnabled:NO oneDMode:NO]; scannerView.displayedMessage = nil; widController = [[ZXingWidgetController alloc]init ]; //set the overlay of widController [widController setOverlayView:scannerView]; QRCodeReader* qrcodeReader = [[QRCodeReader alloc] init]; NSSet *readers = [[NSSet alloc ] initWithObjects:qrcodeReader,nil]; [qrcodeReader release]; widController.readers = readers; widController.delegate = self; [readers release]; [scannerView release]; NSBundle *mainBundle = [NSBundle mainBundle]; widController.soundToPlay = [NSURL fileURLWithPath:[mainBundle pathForResource:@"beep-beep" ofType:@"aiff"] isDirectory:NO]; //Add scanner to the view [self.view addSubview:widController.view]; 

现在ZXingWidgetController的摄像头视图根本不可见。 有没有人为Zxing定制覆盖层? 我似乎没有发现任何类似的问题。

使用ZXing,您可以直接访问叠加视图并添加/更改其子视图。 例如,将imageview放在这个概览的顶部,如下所示:

 ZXingWidgetController *widController = [[ZXingWidgetController alloc] initWithDelegate:self showCancel:YES OneDMode:NO]; UIImage *qrOverlayImage = [UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"overlay-image" ofType:@"png"]]; UIImageView *qrOverlayImageView = [[[UIImageView alloc] initWithImage:qrOverlayImage] autorelease]; qrOverlayImageView.contentMode = UIViewContentModeScaleAspectFit; qrOverlayImageView.backgroundColor = [UIColor clearColor]; [widController.overlayView addSubview:qrOverlayImageView]; 

使用PNG透明度,添加UILabels等编程创build自定义覆盖。

只需要小心的考虑; 使用Xcode 4.4testingMountain Lion我无法使用ZBar编译我的现有项目之一。 我不能说ZBar是否将被更新为与Xcode 4.4一起工作,或者Xcode 4.4中是否会改变ZBar的工作。 谁知道!

我已经更新了我的项目来使用Zxing,即使它很难得到工作和configuration它。

更新 :我现在开始使用ZXingObjC( https://github.com/TheLevelUp/ZXingObjC )。 Zxing的工作比Zxing更容易,而Zxing中也缺less很多function。