ZBar SDK(iOS):当我使用子视图时,Zbar不扫描

时间:2013-04-04 19:17:53

标签: ios6 sdk subview zbar-sdk

我在其他项目中使用过成功使用的ZBar,但是在将其实现到我的最新项目时遇到了问题。它被设置为选项卡式视图应用程序,其中第一个选项卡是扫描仪,第二个选项卡输出结果。为了解决使用全屏而不显示标签栏的ZBar问题,我创建了一个子视图(参见下面的代码)。但是,我也在我的其他ZBar项目上对此进行了测试,当您使用子视图时,ZBar不会读取条形码然后存储编码数据。相反,动画扫描示踪剂只是反弹。

我可以在代码中添加一些内容,以便在子视图中使用ZBar吗?或者这是在标签应用程序中使用ZBar的错误方法吗?

这是我的扫描方法:

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

}

2 个答案:

答案 0 :(得分:3)

这适用于UITabBarController - (图片)http://db.tt/cgVxDd0x

我认为您的问题是您没有设置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);

}

答案 1 :(得分:0)

我也遇到过这种问题。但是,一旦我将读者对象变成了全局对象而不是本地对象,那么这种方法就可以了。