I've used successfully used ZBar in other projects, but am having problems implementing it into my latest project. It is set up as a tabbed view app, where the first tab is the scanner and the second outputs the results. To get around the issue of ZBar using full screen and not displaying the tab bar, I created a subview (see code below). However, and I've tested this on my other ZBar projects as well, when you use a subview, ZBar does not ever read the barcode and then store the encoded data. Instead, the animated scan tracer just bounces around.
Is there something that I can add to my code that would allow me to use ZBar in subview? Or is this the wrong way to go about using ZBar in a tabbed app?
Here is my scan method:
- (void) presentReader
{
ZBarReaderViewController *reader = [ZBarReaderViewController new];
reader.readerDelegate = self;
reader.supportedOrientationsMask = ZBarOrientationMask(UIInterfaceOrientationPortrait);
reader.showsHelpOnFail = YES;
NSLog(@"reader presented");
ZBarImageScanner *scanner = reader.scanner;
// TODO: (optional) additional reader configuration here
// EXAMPLE: disable rarely used I2/5 to improve performance
[scanner setSymbology: 0
config: ZBAR_CFG_ENABLE
to: 0];
[scanner setSymbology: ZBAR_UPCA
config: ZBAR_CFG_ENABLE
to: 0];
[scanner setSymbology: ZBAR_DATABAR
config: ZBAR_CFG_ENABLE
to: 1];
[scanner setSymbology: ZBAR_DATABAR_EXP
config: ZBAR_CFG_ENABLE
to: 1];
reader.showsCameraControls = NO; // for UIImagePickerController
reader.showsZBarControls = NO;
//reader.cameraFlashMode = UIImagePickerControllerCameraFlashModeAuto;
reader.wantsFullScreenLayout = NO;
reader.videoQuality = UIImagePickerControllerQualityTypeIFrame1280x720;
//Subview
[self.view addSubview:reader.view];
}
this works for me in a UITabBarController - (Image) http://db.tt/cgVxDd0x
I think your problem was that you weren't setting reader.scanCrop.
-(void) viewDidAppear:(BOOL)animated {
self.reader = [ZBarReaderViewController new];
self.reader.readerDelegate = self;
self.reader.enableCache = NO;
self.reader.showsZBarControls = NO;
self.reader.wantsFullScreenLayout = NO;
self.reader.cameraFlashMode = UIImagePickerControllerCameraFlashModeOff;
self.reader.supportedOrientationsMask = ZBarOrientationMask(UIInterfaceOrientationPortrait);
ZBarImageScanner *scanner = self.reader.scanner;
[scanner setSymbology: ZBAR_I25
config: ZBAR_CFG_ENABLE
to: 0];
self.reader.scanCrop = CGRectMake(0, 0, 1, 1);
[self.view addSubview:self.reader.view];
}
- (void) imagePickerController: (UIImagePickerController*) reader didFinishPickingMediaWithInfo: (NSDictionary*) info {
id<NSFastEnumeration> results = [info objectForKey: ZBarReaderControllerResults];
ZBarSymbol *symbol = nil;
for(symbol in results)
break;
NSLog(@"%@",symbol.data);
}