简体   繁体   English

iOS 加载覆盖不覆盖整个屏幕

[英]iOS Loading overlay does not cover the whole screen

I'm trying to display an overlay during an auto login HTTP call.我正在尝试在自动登录 HTTP 调用期间显示叠加层。 I've found this code , which seems outdated somehow, but found nothing more recent.我发现了这段代码,它似乎已经过时了,但没有找到更新的内容。

Anyway, the Overlay is showing but not covering the whole screen as expected.无论如何,叠加显示但未按预期覆盖整个屏幕。

The calling code is this:调用代码是这样的:

AppDelegate.FinishedLaunching AppDelegate.FinishedLaunching

var avc = new AutoLoginViewController();
var navController = new UINavigationController(avc);

AutoLoginViewController.ViewDidLoad 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);

But the result is the following:但结果如下:

LoadOverlay 大小不正确

If I set a breakpoint in the LoadingOverlay constructor, I can see that the screen bounds (iPhone 6) are fine:如果我在 LoadingOverlay 构造函数中设置断点,我可以看到屏幕边界(iPhone 6)很好:

{{X=0,Y=0,Width=375,Height=667}} {{X=0,Y=0,宽度=375,高度=667}}

public class LoadingOverlay : UIView
{
    public LoadingOverlay(CGRect frame, string text) : base(frame)
    {
       // configurable bits
       BackgroundColor = UIColor.Black;
       Alpha = 0.75f;
       AutoresizingMask = UIViewAutoresizing.FlexibleDimensions;
       ...
    }
}

Clearly the UIView width is incorrect.显然 UIView 宽度不正确。

Because we're in 2020, maybe there is another way.因为我们在 2020 年,也许还有另一种方式。

Any help appreciated.任何帮助表示赞赏。


EDIT: The app breaks on iPhone 8 iOS 13.3 simulator, So I can't say if this is tied to a particular screen size (1x in my case).编辑:该应用程序在 iPhone 8 iOS 13.3 模拟器上中断,所以我不能说这是否与特定的屏幕尺寸有关(在我的情况下为 1x)。

Cause :原因 :

It seems that you didn't set the LaunchImage , So whether on a simulator or real device , the value of bounds is a static value .好像你没有设置LaunchImage ,所以不管是模拟器还是真机,bounds 的值都是静态值。

Solution:解决方案:

The easiest way is set the size of overlay as bounds of View .最简单的方法是将覆盖的大小设置为 View 的边界。

var bounds = View.Bounds;

Or you could set all size of LaunchImage of different screen .或者您可以设置不同屏幕的 LaunchImage 的所有大小。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM