【问题标题】:Xamarin Forms Shell covering top information line on iOS (iPad)Xamarin Forms Shell 覆盖 iOS (iPad) 上的顶级信息行
【发布时间】:2019-10-31 09:21:04
【问题描述】:

我有一个使用新 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 安全区域后,该应用在我看来是一样的:

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

【问题讨论】:

  • 嗯,我不确定是什么问题,截图似乎没有区别!
  • @FreakyAli 如果你看第二张图片,你可以看到 Shell 菜单顶部的深色背景颜色一直到屏幕顶部,越过日期/时间等。
  • @GeorgeMCeaserJr 很抱歉不了解您的需求。你可以分享一张想要的图片来解释一下,会有帮助的。
  • @JuniorJiang,第一张图片中剪下的顶部 iPad 就是我要找的。我希望外壳(及其背景)不要进入屏幕最顶部的日期/时间、网络/电源区域。
  • @GeorgeMCeaserJr Okey,我已经分享了一个解决方法。

标签: ios xamarin.forms padding xamarin.shell


【解决方案1】:

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

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

添加两个key-value修改状态栏内容的样式,

<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.cs添加方法将状态栏的背景颜色设置为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;
        }
    }
}

如下图:

效果:

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

【讨论】:

  • 谢谢@JuiorJiang。我会让你知道我是怎么理解这个的。
【解决方案2】:

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

【讨论】:

  • 感谢您的信息。我一定会把它包含在我的应用程序中,但它并没有解决我试图解决的挑战。我在上面发布了一个屏幕截图,显示了已实现安全区域的页面外观。我看起来和以前一样。请参阅上面的更新以获取屏幕截图。
  • 很抱歉没有这样,我忘了你可以改变系统栏的外观。您应该查看Junior Jiang的答案,我认为这将引导您走向正确的方向
猜你喜欢
  • 2018-12-22
  • 2018-02-14
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-11-25
  • 1970-01-01
相关资源
最近更新 更多