ios - 如何使 BarcodeScanner 插件在横向模式下工作?
<p><p>我正在使用 Cordova 开发 iOS 应用程序,我从 <a href="https://github.com/wildabeast/BarcodeScanner/" rel="noreferrer noopener nofollow">link</a> 下载了 Cordova 条形码扫描仪插件。 .</p>
<p>但是,它只适用于纵向模式。</p>
<p>我对 CDVBarcodeScanner.mm 进行了一些更改。</p>
<pre><code>#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) && ) {
return ;
}
return YES;
}
- (void) willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)orientation duration:(NSTimeInterval)duration
{
// ;
//
// self.processor.previewLayer.orientation = orientation;
// ;
// self.processor.previewLayer.frame = self.view.bounds;
//
// ;
// ;
;
AVCaptureVideoPreviewLayer* previewLayer = self.processor.previewLayer;
previewLayer.frame = self.view.bounds;
if (orientation == UIInterfaceOrientationLandscapeLeft) {
;
} else if (orientation == UIInterfaceOrientationLandscapeRight) {
;
} else if (orientation == UIInterfaceOrientationPortrait) {
;
} else if (orientation == UIInterfaceOrientationPortraitUpsideDown) {
;
}
previewLayer.videoGravity = AVLayerVideoGravityResizeAspectFill;
;
}
</code></pre>
<p>我现在可以旋转到横向模式,但它仍然只能在纵向模式下工作。
我该如何解决?</p>
<hr/>
<p>根据<a href="https://stackoverflow.com/questions/10945976/zxing-barcode-scanner-phonegap-plugin-ios-landscape-mode?rq=1" rel="noreferrer noopener nofollow">solution</a> ,我删除 <em>zxing-all-in-one.cpp</em> 中的 <strong>if (result.empty() && hints.getTryHarder() && image->isRotateSupported()) {}</strong> .</p>
<p>但是,它现在只适用于横向。</p></p>
<br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
<p><p>在 zxing-all-in-one.cpp 文件中,</p>
<p>改变</p>
<pre><code>if (result.empty() && hints.getTryHarder() && image->isRotateSupported()) {}
</code></pre>
<p>到</p>
<pre><code>if (result.empty()) {}
</code></pre></p>
<p style="font-size: 20px;">关于ios - 如何使 BarcodeScanner 插件在横向模式下工作?,我们在Stack Overflow上找到一个类似的问题:
<a href="https://stackoverflow.com/questions/17280994/" rel="noreferrer noopener nofollow" style="color: red;">
https://stackoverflow.com/questions/17280994/
</a>
</p>
页:
[1]