iOS Loading overlay does not cover the whole screen

149 views Asked by At

I'm trying to display an overlay during an auto login HTTP call. 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

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);

But the result is the following:

LoadOverlay incorrect size

If I set a breakpoint in the LoadingOverlay constructor, I can see that the screen bounds (iPhone 6) are fine:

{{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;
       ...
    }
}

Clearly the UIView width is incorrect.

Because we're in 2020, maybe there is another way.

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).

1

There are 1 answers

0
Lucas Zhang On BEST ANSWER

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 .

Solution:

The easiest way is set the size of overlay as bounds of View .

var bounds = View.Bounds;

Or you could set all size of LaunchImage of different screen .