2

我正在使用 Cordova 开发 iOS 应用程序,并从此链接下载 Cordova Barcode Scanner Plugin 。

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

我在 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];
}

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


根据解决方案,我删除了zxing-all-in-one.cpp 中的if (result.empty() && hints.getTryHarder() && image->isRotateSupported()) {}

但是,它现在仅适用于横向。

4

2 回答 2

1

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

改变

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

if (result.empty()) {}
于 2013-06-24T20:53:26.593 回答
0

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

于 2014-03-26T15:24:28.523 回答