Maui 在 IOS 13+ 中隐藏状态栏

问题描述 投票:0回答:2

下面的代码有效,但已过时。我正在寻找更好的解决方案。

    UIApplication.SharedApplication.SetStatusBarHidden(shouldBeFullScreen, animation: UIKit.UIStatusBarAnimation.Fade);

我需要使用

UIViewController PrefersStatusBarHidden();

我试过:

UIWindow window = UIApplication.SharedApplication.Delegate.GetWindow();

        var vc = window?.RootViewController ?? WindowStateManager.Default.GetCurrentUIViewController() ?? throw new InvalidOperationException($"{nameof(window.RootViewController)} cannot be null");
        while (vc.PresentedViewController is not null)
        {
            vc = vc.PresentedViewController;
        }
            vc.PrefersStatusBarHidden();
            vc.SetNeedsStatusBarAppearanceUpdate();

上面的代码确实抓取了窗口,但实际上并没有隐藏状态栏。

我也试过:

Microsoft.Maui.Controls.PlatformConfiguration.iOSSpecific.Page.SetPrefersStatusBarHidden(currentPage, item);

如有任何建议,我们将不胜感激。我正致力于在社区工具包的媒体元素中实现全屏控件,但我一直坚持在 IOS 中隐藏状态栏。

ios maui maui-community-toolkit
2个回答
0
投票

将以下行添加到您的 info.plist 文件中。右键单击 info.plist 并选择 Open As 然后选择 Source Code

<key>UIStatusBarHidden</key>
<true/>
<key>UIViewControllerBasedStatusBarAppearance</key>
<false/>

0
投票

您可以将 StatusBarHidden 的值设置为 true 或 false。

假设您有一个按钮单击处理程序来控制 StatusBar 的外观。考虑以下我的解决方法:

#if IOS
    using UIKit;
#endif


private async void OnCounterClicked(object sender, EventArgs e)
{
    ......
#if IOS
    UIApplication.SharedApplication.StatusBarHidden = !UIApplication.SharedApplication.StatusBarHidden;
#endif
    ....
}

同时在info.plist中设置如下键值:

<key>UIViewControllerBasedStatusBarAppearance</key>
<false/>

希望它有效。

© www.soinside.com 2019 - 2024. All rights reserved.