。 我有以下问题使用iPhone 16时出现的问题。 毛伊岛应用程序不使用shell,如果这可能以任何方式有用... 这里有一个完整的毛伊示例项目 解释 Pro ...

问题描述 投票:0回答:0
有一个完整的毛伊示例项目

解释 问题似乎不是出现在iPad或任何Android设备上,而是在所有具有更大状态栏的iPhone上。 我正在使用

CommunityToolkit.Maui Version 9.0.3

为状态栏着色。 这里是我的CSPROJ的片段,查看我正在使用的Nuget软件包:spacing_problem <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>

希望有帮助

	

c# ios iphone xaml maui
最新问题
© www.soinside.com 2019 - 2025. All rights reserved.