我正在尝试在自动登录HTTP呼叫期间显示覆盖图。我找到了this code,它似乎已经过时了,但是最近没有发现。
无论如何,叠加层正在显示,但没有按预期覆盖整个屏幕。
调用代码是这里:
AppDelegate.FinishedLaunching
var avc = new AutoLoginViewController();
var navController = new UINavigationController(avc);
AutoLoginViewController.ViewDidLoad
var bounds = UIScreen.MainScreen.Bounds;
// show the loading overlay on the UI thread using the correct orientation sizing
loadPop = new LoadingOverlay(bounds, NSBundle.MainBundle.GetLocalizedString("connecting"));
View.Add(loadPop);
但是结果如下:
如果我在LoadingOverlay构造函数中设置断点,则可以看到屏幕边界(iPhone 6)很好:
{{X = 0,Y = 0,Width = 375,Height = 667}}]
public class LoadingOverlay : UIView
{
public LoadingOverlay(CGRect frame, string text) : base(frame)
{
// configurable bits
BackgroundColor = UIColor.Black;
Alpha = 0.75f;
AutoresizingMask = UIViewAutoresizing.FlexibleDimensions;
...
}
}
显然UIView宽度不正确。
因为我们在2020年,也许还有另一种方式。
感谢任何帮助。
编辑:该应用程序在iPhone 8 iOS 13.3模拟器上中断,因此我不能说这是否与特定的屏幕尺寸(在我的情况下为1倍)相关。
原因:
似乎您没有设置LaunchImage,所以无论在模拟器还是真实设备上,bounds的值都是静态值。
解决方案:
最简单的方法是将叠加层的大小设置为View的边界。
var bounds = View.Bounds;
或者您可以设置不同屏幕的LaunchImage的所有大小。