【问题标题】:modifying zxing library files barcode scanner iPhone修改 zxing 库文件条码扫描器 iPhone
【发布时间】:2011-11-10 13:56:12
【问题描述】:

我想稍微修改一下 zxing 库文件(这是一个开源库),以便在用户点击扫描按钮打开条形码扫描仪相机时立即打开 cameraFlashMode。另外,我想在底部添加一两个 UIButton。简而言之,我想根据我的需要自定义那个相机视图。 如果有人做过或知道怎么做,请帮助我。

【问题讨论】:

  • 有人请给我一个答案。我迫切需要它。我是否必须使用 AVDeviceCapture 来访问相机,因为在 zxing 库中,我无法找到相机的 UIImagePickerViewController。

标签: iphone objective-c ios


【解决方案1】:

您需要在 OverlayView.m 中实现您的自定义。添加按钮

- (id) initWithFrame:(CGRect)theFrame cancelEnabled:(BOOL)isCancelEnabled oneDMode:(BOOL)isOneDModeEnabled;

并在ZXingWidgetController.h中设置flashmode

- (void)initCapture;

使用以下命令设置 flashMode:

- (void)activateFlash {
    Class captureDeviceClass = NSClassFromString(@"AVCaptureDevice");
    if (captureDeviceClass != nil) {

        AVCaptureDevice *device = [AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeVideo];

        [device lockForConfiguration:nil];
        if ( [device hasFlash] ) {
            [device setFlashMode:AVCaptureFlashModeOn];
        }
        [device unlockForConfiguration];
    }
}

【讨论】: