从PageRenderer隐藏iOS中的状态栏

时间:2016-08-12 07:57:09

标签: c# ios xamarin xamarin.ios

是否可以在PageRenderer中隐藏状态栏?

我尝试在Info.plist

中设置这些内容
<key>UIStatusBarHidden</key>
<true/>
<key>UIViewControllerBasedStatusBarAppearance</key>
<true/>

然后将PrefersStatusBarHidden中的PageRenderer覆盖为

public override bool PrefersStatusBarHidden()
{
   return true;
}

如果我将UIViewControllerBasedStatusBarAppearance中的Info.plist设置为false,则会隐藏在所有网页上。

我该如何解决这个问题?

1 个答案:

答案 0 :(得分:2)

您应该使用自定义UINavigationController而不是系统UINavigationController,如下例所示:

在AppDelegate.cs中:

UINavigationController navController;
    UIWindow window;

    public override bool FinishedLaunching (UIApplication application, NSDictionary launchOptions)
    {
        navController = new UINavigationController (new TestViewCtonroller ());

        // create a new window instance based on the screen size
        window = new UIWindow (UIScreen.MainScreen.Bounds);
        window.RootViewController = navController;
        window.MakeKeyAndVisible ();

        return true;
    }

MyNavigationController.cs:

public class MyNavigationController : UINavigationController
{
    public MyNavigationController (UIViewController rootController) : base(rootController)
    {
    }

    public override UIViewController ChildViewControllerForStatusBarHidden ()
    {
        return TopViewController;
    }

    public override UIViewController ChildViewControllerForStatusBarStyle ()
    {
        return TopViewController;
    }
}

TestViewCtonroller.cs:

public class TestViewCtonroller : UIViewController
{
    public TestViewCtonroller ()
    {
        this.View.BackgroundColor = UIColor.Red;
    }

    public override UIStatusBarStyle PreferredStatusBarStyle ()
    {
        return UIStatusBarStyle.LightContent;
    }

    public override bool PrefersStatusBarHidden ()
    {
        return true;
    }
}

希望它可以帮到你。