1

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];

}
user1486548
  • 1,201
  • 4
  • 15
  • 22

2 Answers2

3

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);

}
Jeremy Roberts
  • 751
  • 1
  • 5
  • 13
  • Thanks! Unfortunately, adding the scan crop didn't fix it. I think I may have something wrong in my AppDelegate...Could you share your AppDelegate code? – user1486548 Apr 12 '13 at 18:20
  • Sure, I made this project for your answer. https://www.dropbox.com/s/dojirkslmpfk8ym/CameraView.zip – Jeremy Roberts Apr 14 '13 at 22:25
  • 1
    Thanks! Incredibly helpful! – user1486548 Apr 15 '13 at 14:09
  • @JeremyRoberts How can I use that code in viewDidLoad??? I have tab bar and want on first tab qr-reader. But if i remove your code from `viewDidAppear` to `viewDidLoad` the image freeze on prev state. – user2545330 Oct 09 '13 at 12:21
0

I am also faced this kind of Problem. But, once I made that reader object into global object instead of local, then this was works fine.