OStack程序员社区-中国程序员成长平台

标题: ios - 如何使 BarcodeScanner 插件在横向模式下工作? [打印本页]

作者: 菜鸟教程小白    时间: 2022-12-12 11:58
标题: ios - 如何使 BarcodeScanner 插件在横向模式下工作?

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

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

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

#pragma mark CDVBarcodeScannerOrientationDelegate

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

- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
    return UIInterfaceOrientationPortrait;
}

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

- (BOOL)shouldAutorotateToInterfaceOrientationUIInterfaceOrientation)interfaceOrientation
{
    if ((self.orientationDelegate != nil) && [self.orientationDelegate respondsToSelectorselector(shouldAutorotateToInterfaceOrientation]) {
        return [self.orientationDelegate shouldAutorotateToInterfaceOrientation:interfaceOrientation];
    }

    return YES;
}

- (void) willAnimateRotationToInterfaceOrientationUIInterfaceOrientation)orientation durationNSTimeInterval)duration
{
//    [CATransaction begin];
//    
//    self.processor.previewLayer.orientation = orientation;
//    [self.processor.previewLayer layoutSublayers];
//    self.processor.previewLayer.frame = self.view.bounds;
//    
//    [CATransaction commit];
//    [super willAnimateRotationToInterfaceOrientationrientation 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 ,我删除 zxing-all-in-one.cpp 中的 if (result.empty() && hints.getTryHarder() && image->isRotateSupported()) {} .

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



Best Answer-推荐答案


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

改变

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

if (result.empty()) {}

关于ios - 如何使 BarcodeScanner 插件在横向模式下工作?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17280994/






欢迎光临 OStack程序员社区-中国程序员成长平台 (https://ostack.cn/) Powered by Discuz! X3.4