如何使BarcodeScanner插件在横向模式下工作?

时间:2013-06-24 17:02:56

标签: ios uiviewcontroller cordova barcode-scanner

我正在使用Cordova开发iOS应用程序,并从此link下载Cordova条形码扫描程序插件。

但是,它仅适用于纵向模式。

我在CDVBarcodeScanner.mm中进行了一些更改。

#pragma mark CDVBarcodeScannerOrientationDelegate

- (BOOL)shouldAutorotate
{   
    return YES;// NO;
}

- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
    return UIInterfaceOrientationPortrait;
}

- (NSUInteger)supportedInterfaceOrientations
{
    return UIInterfaceOrientationMaskAll; // UIInterfaceOrientationMaskPortrait;
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    if ((self.orientationDelegate != nil) && [self.orientationDelegate respondsToSelector:@selector(shouldAutorotateToInterfaceOrientation:)]) {
        return [self.orientationDelegate shouldAutorotateToInterfaceOrientation:interfaceOrientation];
    }

    return YES;
}

- (void) willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)orientation duration:(NSTimeInterval)duration
{
//    [CATransaction begin];
//    
//    self.processor.previewLayer.orientation = orientation;
//    [self.processor.previewLayer layoutSublayers];
//    self.processor.previewLayer.frame = self.view.bounds;
//    
//    [CATransaction commit];
//    [super willAnimateRotationToInterfaceOrientation:orientation duration:duration];

    [UIView setAnimationsEnabled:NO];
    AVCaptureVideoPreviewLayer* previewLayer = self.processor.previewLayer;
    previewLayer.frame = self.view.bounds;

    if (orientation == UIInterfaceOrientationLandscapeLeft) {
        [previewLayer setOrientation:AVCaptureVideoOrientationLandscapeLeft];
    } else if (orientation == UIInterfaceOrientationLandscapeRight) {
        [previewLayer setOrientation:AVCaptureVideoOrientationLandscapeRight];
    } else if (orientation == UIInterfaceOrientationPortrait) {
        [previewLayer setOrientation:AVCaptureVideoOrientationPortrait];
    } else if (orientation == UIInterfaceOrientationPortraitUpsideDown) {
        [previewLayer setOrientation:AVCaptureVideoOrientationPortraitUpsideDown];
    }

    previewLayer.videoGravity = AVLayerVideoGravityResizeAspectFill;
    [UIView setAnimationsEnabled:YES];
}

我现在可以旋转到横向模式,但它仍然只能在纵向模式下工作。 我该如何解决?


根据solution,我删除 if(result.empty()&& hints.getTryHarder()&& image-> isRotateSupported()){} zxing-all-in-one.cpp

但是,它现在只适用于风景。

2 个答案:

答案 0 :(得分:1)

在zxing-all-in-one.cpp文件中,

变化

if (result.empty() && hints.getTryHarder() && image->isRotateSupported()) {}

if (result.empty()) {}

答案 1 :(得分:0)

您还可以修改CDVBarcodeScanner.mm。只需用LandscapeLeft / LandscapeRight替换所有***肖像 - >我更喜欢LandscapeLeft。