0

我有一个使用新 Shell 功能的 Xamarin Forms 应用程序。我现在的问题是外壳菜单区域(顶部的汉堡菜单区域)被我的应用程序覆盖,我不希望它被覆盖。

这就是我所说的。

在此处输入图像描述

您可以在我的应用程序的第二张图片中看到顶部带有数据和时间的区域。我希望情况并非如此。

在其他应用程序中,我在内容页面上完成了此操作:

<ContentPage.Padding>
    <OnPlatform x:TypeArguments="Thickness">
        <On Platform="iOS">8,20,8,0</On>
        <On Platform="Android">8,0,8,0</On>
        <On Platform="UWP">8,0,8,0</On>
    </OnPlatform>
</ContentPage.Padding>

在我尝试过的 Shell 页面中:

<Shell.Padding>
    <OnPlatform x:TypeArguments="Thickness">
        <On Platform="iOS">8,20,8,0</On>
        <On Platform="Android">8,0,8,0</On>
        <On Platform="UWP">8,0,8,0</On>
    </OnPlatform>
</Shell.Padding>

但这没有什么区别。知道如何使 Shell 菜单不覆盖日期/时间吗?

更新:如下所述应用 iOS 安全区域后,该应用程序在我看来看起来相同:

在此处输入图像描述

数据和时间背后的背景仍然是外壳标题的背景颜色(即黑色),因此您无法真正看到它们。我希望外壳向下移动,以便用户仍然可以看到左侧的日期/时间,右侧的网络/收费指示器。

4

2 回答 2

0

由于 iOS 11 及更高版本,我强烈建议您尝试在 iOS 中设置安全区域,这相当简单,可能会解决您的问题:https ://docs.microsoft.com/en-us/xamarin/xamarin-forms/platform/ ios/页面安全区域布局

于 2019-10-28T10:17:03.063 回答
0

通过修改状态栏文本颜色来标记它,我有一个解决方法。如果您的应用导航背景颜色始终保持深色样式,则此解决方法将没有问题。但是它不是一个完美的解决方案。因为它无法在运行时修改。在找到最佳解决方案之前,您可以尝试一下。

解决方法是需要在 iOS 解决方案中打开Info.plist

在此处输入图像描述

添加两个键值来修改状态栏内容的样式,

<string>Assets.xcassets/AppIcon.appiconset</string>
<key>UIViewControllerBasedStatusBarAppearance</key>
<false/>
<key>UIStatusBarStyle</key>
<string>UIStatusBarStyleLightContent</string>

在此处输入图像描述

然后即使导航栏的颜色是黑色的,也会看到状态栏的文本颜色。

在此处输入图像描述

第二个解决方法:(比第一个好)

还需要在 iOS 解决方案中打开Info.plist,但只需在其中添加一个 key-value 即可。

<string>Assets.xcassets/AppIcon.appiconset</string>
<key>UIViewControllerBasedStatusBarAppearance</key>
<false/>

然后在AppDelegate.csadd 方法中将状态栏的背景颜色设置为White彩色。

public override void OnActivated(UIApplication uiApplication)
{
    base.OnActivated(uiApplication);
    if (UIDevice.CurrentDevice.CheckSystemVersion(13, 0))
    {
        // If VS has updated to the latest version , you can use StatusBarManager , else use the first line code
        // UIView statusBar = new UIView(UIApplication.SharedApplication.StatusBarFrame);
        UIView statusBar = new UIView(UIApplication.SharedApplication.KeyWindow.WindowScene.StatusBarManager.StatusBarFrame);
        statusBar.BackgroundColor = UIColor.White;
        //statusBar.TintColor = UIColor.White;
        UIApplication.SharedApplication.KeyWindow.AddSubview(statusBar);
    }
    else
    {
        UIView statusBar = UIApplication.SharedApplication.ValueForKey(new NSString("statusBar")) as UIView;
        if (statusBar.RespondsToSelector(new ObjCRuntime.Selector("setBackgroundColor:")))
        {
            statusBar.BackgroundColor = UIColor.White;
            //statusBar.TintColor = UIColor.White;
            UIApplication.SharedApplication.StatusBarStyle = UIStatusBarStyle.BlackOpaque;
        }
    }
}

图片如下:

在此处输入图像描述

效果:

在此处输入图像描述

注意:如果以后找到更好的解决方法将在此处更新。

于 2019-10-29T02:24:33.113 回答