Xamarin.iOS状态栏在更改颜色和在iPad上的方向时将颜色保留在角落里

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

我的应用程序支持iOS系统暗模式更改。但是状态栏颜色有点棘手,但最后我还是设法对其进行了更改。

我的问题是,当您在iPad上使用纵向模式时,切换主题,然后将iPad倾斜至横向模式时,状态栏的扩展将保留旧颜色(请参见下面的屏幕截图)

我不知道这只是一个讨厌的错误还是我做错了什么。如果这是一个错误,我希望对此有一个解决方法。

这是我如何更改CustomRenderer中的状态栏颜色(在此示例中为灯光模式)

if (UIDevice.CurrentDevice.CheckSystemVersion(13, 0))
{
    UIView statusBar = new UIView(UIApplication.SharedApplication.KeyWindow.WindowScene.StatusBarManager.StatusBarFrame);
    statusBar.BackgroundColor = Color.FromHex("#FFFFFF").ToUIColor();
    UIApplication.SharedApplication.KeyWindow.AddSubview(statusBar);
}
this.NavigationController.NavigationBar.BarTintColor = Color.FromHex("#FFFFFF").ToUIColor();

这在TraitCollectionDidChange函数中被调用。

enter image description here

ios xamarin xamarin.ios ios-darkmode
1个回答
0
投票

这是因为您使用Frame添加了自定义状态栏。当它碰到风景时,其宽度仍然是肖像的值。尝试将其更改为自动布局,例如:

if (UIDevice.CurrentDevice.CheckSystemVersion(13, 0))
{
    UIView statusBar = new UIView();
    statusBar.TranslatesAutoresizingMaskIntoConstraints = false;
    statusBar.BackgroundColor = UIColor.White;
    UIApplication.SharedApplication.KeyWindow.AddSubview(statusBar);

    statusBar.LeadingAnchor.ConstraintEqualTo(UIApplication.SharedApplication.KeyWindow.LeadingAnchor).Active = true;
    statusBar.TopAnchor.ConstraintEqualTo(UIApplication.SharedApplication.KeyWindow.TopAnchor).Active = true;
    statusBar.TrailingAnchor.ConstraintEqualTo(UIApplication.SharedApplication.KeyWindow.TrailingAnchor).Active = true;
    statusBar.HeightAnchor.ConstraintEqualTo(UIApplication.SharedApplication.KeyWindow.WindowScene.StatusBarManager.StatusBarFrame.Height).Active = true;
}
© www.soinside.com 2019 - 2024. All rights reserved.