解释 问题似乎不是出现在iPad或任何Android设备上,而是在所有具有更大状态栏的iPhone上。 我正在使用
CommunityToolkit.Maui Version 9.0.3
为状态栏着色。
这里是我的CSPROJ的片段,查看我正在使用的Nuget软件包:
<ItemGroup>
<PackageReference Include="Microsoft.Maui.Controls" Version="$(MauiVersion)" />
<PackageReference Include="CommunityToolkit.Maui" Version="9.0.3" />
<PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="9.0.0" />
</ItemGroup>
MainPage.xaml
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:toolkit="http://schemas.microsoft.com/dotnet/2022/maui/toolkit"
NavigationPage.HasBackButton="False"
NavigationPage.HasNavigationBar="False"
x:Class="MauiApp1.MainPage">
<ContentPage.Behaviors>
<toolkit:StatusBarBehavior
StatusBarColor="#BE0C24"
StatusBarStyle="LightContent"/>
</ContentPage.Behaviors>
<Grid BackgroundColor="Yellow">
<Label VerticalOptions="Start" BackgroundColor="Green" Text="^^^ I want to get rid of that yellow space ^^^"/>
</Grid>
</ContentPage>
OnAppearing
的情况下都提供了类似的解决方法:
protected override void OnAppearing()
{
base.OnAppearing();
#if IOS
// Workaround for iPhone 14: https://developer.apple.com/forums/thread/715417
if (UIDevice.CurrentDevice.CheckSystemVersion(13, 0))
{
var window = UIKit.UIApplication.SharedApplication.Windows.FirstOrDefault();
var topPadding = window?.SafeAreaInsets.Top ?? 0;
var statusBar = new UIView(new CoreGraphics.CGRect(0, 0, UIScreen.MainScreen.Bounds.Size.Width, topPadding))
{
BackgroundColor = Colors.Green.ToPlatform()
};
var view = UIApplication.SharedApplication.Windows.FirstOrDefault(x => x.IsKeyWindow);
view?.AddSubview(statusBar);
}
#endif
}
将其添加到我的代码中,没有任何更改。
我还尝试过像这篇文章一样禁用安全空间。
。
IgnoreSafeArea="True"
忽略(大惊喜)状态栏完全安全空间,看起来像这样:
我认为该解决方案必须以某种方式将标签转移到网格顶部或扩大红色区域...
我仍然想知道为什么网格甚至添加了这种填充,但即使将填充设置为0也没有效果。
我现在不知道该尝试什么...<Grid BackgroundColor="Yellow">
<Label Margin="0,-5,0,0" VerticalOptions="Start" BackgroundColor="Green" Text="^^^ I want to get rid of that yellow space ^^^"/>
</Grid>
希望有帮助