[英]ZXing Xamarin forms white background on IOS
Xamarin.Forms的ZXing条码扫描器存在问题。 扫描仪可以在Android上完美运行,但是在IOS上我看不到相机图像(预览)。 如果我将条形码放在IOS的前面,则扫描仪会在IOS上扫描条形码,但摄像机预览只是白色背景。
我尝试玩这些选项,但没有运气。 我们正在将Prism.Forms用于MVVM。
如前所述,我的代码在android上运行良好。 以下是一些详细信息:
ScannerView.xaml
<forms:ZXingScannerPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:forms="clr-namespace:ZXing.Net.Mobile.Forms;assembly=ZXing.Net.Mobile.Forms"
x:Class="App.Portable.View.ScannerView">
<ContentPage.Content>
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<forms:ZXingScannerView x:Name="scanner" Grid.Column="0" Grid.Row="0" HorizontalOptions="EndAndExpand" VerticalOptions="FillAndExpand"
IsScanning="{Binding IsScanning}"
IsAnalyzing="{Binding IsAnalyzing}"
Result="{Binding Result, Mode=TwoWay}"
ScanResultCommand="{Binding CmdScanResult}"
Options="{Binding ScannerOptions}"
/>
<forms:ZXingDefaultOverlay Grid.Column="0" Grid.Row="0"
TopText="Some title"
ShowFlashButton="False"
BottomText="Some bottom text"
Opacity="0.9"/>
</Grid>
</ContentPage.Content>
ScannerViewModel.cs
public class ScannerViewModel : ViewModelBase
{
//Initializing variables
public ScannerViewModel()
{
var options = new MobileBarcodeScanningOptions();
options.TryHarder = true;
options.InitialDelayBeforeAnalyzingFrames = 300;
options.DelayBetweenContinuousScans = 100;
options.DelayBetweenAnalyzingFrames = 200;
options.AutoRotate = false;
ScanningOptions = options;
Title = "Barcode-Scanner";
CmdScanResult = new DelegateCommand(OnCmdScanResult);
IsScanning = true;
IsAnalyzing = true;
}
public MobileBarcodeScanningOptions ScanningOptions
{
get => _scanningOptions;
set => SetProperty(ref _scanningOptions, value);
}
public bool IsScanning
{
get => _isScanning;
set => SetProperty(ref _isScanning, value);
}
public bool IsAnalyzing
{
get => _isAnalyzing;
set => SetProperty(ref _isAnalyzing, value);
}
public Result Result
{
get => _result;
set => SetProperty(ref _result, value);
}
public DelegateCommand CmdScanResult { get; }
private void OnCmdScanResult()
{
IsAnalyzing = false;
IsScanning = false;
Device.BeginInvokeOnMainThread(
async () =>
{
IsAnalyzing = false;
var parameters = new NavigationParameters();
parameters.Add(CodeConstants.BARCODE, Result);
await NavigationService.GoBackAsync(parameters);
});
}
}
是否有人在我的代码上看到问题,或者对如何做得更好或至少使其起作用有建议?
编辑:我将Testproject上传到我的仓库以重现该错误。 扫描仪可在iPhone上运行,但不显示相机预览: https : //gitlab.com/mitti2000/zxingtest
原因:将ZXingScannerView和ZXingDefaultOverlay放在网格的同一单元格中,然后将ZXingScannerView的HorizontalOptions
设置为EndAndExpand
。
解:
HorizontalOptions="FillAndExpand" VerticalOptions="FillAndExpand"
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.