gpt4 book ai didi

ios - 如何让 BarcodeScanner 插件在横向模式下工作?

转载 作者:塔克拉玛干 更新时间:2023-11-02 21:42:23 24 4
gpt4 key购买 nike

我正在使用 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 ,我删除 zxing-all-in-one.cpp 中的 if (result.empty() && hints.getTryHarder() && image->isRotateSupported()) {} .

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

最佳答案

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

改变

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

if (result.empty()) {}

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

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com