是否可以在PageRenderer中隐藏状态栏?
我尝试在Info.plist
<key>UIStatusBarHidden</key>
<true/>
<key>UIViewControllerBasedStatusBarAppearance</key>
<true/>
然后将PrefersStatusBarHidden
中的PageRenderer
覆盖为
public override bool PrefersStatusBarHidden()
{
return true;
}
如果我将UIViewControllerBasedStatusBarAppearance
中的Info.plist
设置为false
,则会隐藏在所有网页上。
我该如何解决这个问题?
答案 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;
}
}
希望它可以帮到你。