2

I don't know what is happening : with every simulator and even with my iPhoneX, the UIScreen.main.bounds are (0.0, 0.0, 320.0, 480.0).

Here's what I put in my AppDelegate

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
    // Override point for customization after application launch.
    window = UIWindow()
    let vc = LoginViewController()
    let navigationController = UINavigationController(rootViewController: vc)
    self.window?.rootViewController = navigationController
    self.window!.makeKeyAndVisible()
    navigationController.setNavigationBarHidden(true, animated: false)
    return true
}

I've done that way for years now, and suddenly it doesn't work, especially on that app. What's going on?

edit: Here's the result

enter image description here

Solution : Don't remove the LaunchScreen.storyboard, the UIScreen.main bases its bounds on that…

petaire
  • 495
  • 1
  • 10
  • 23
  • First you should design you UI so that it doesn't care about actual dimensions and make it adapt to different sizes without knowing those sizes. Having said that what is the green area? Is it the size of a view controller view and image or something else? – Upholder Of Truth Jan 21 '18 at 10:25
  • Nope you should first have your uiwindow with the correct bounds. Clemens has the right answer. – petaire Jan 21 '18 at 10:26
  • 1
    You should never need to directly set the bound of your root UIWindow. – Upholder Of Truth Jan 21 '18 at 10:28
  • I didn't say that I wanted to set those… – petaire Jan 21 '18 at 10:29
  • You should be able to design an entire app without once caring about what the size of the physical UIScreen is. Now there are certain instances where you might need to know but they are rare. – Upholder Of Truth Jan 21 '18 at 10:30
  • Yeah thanks Captain Obvious, that was exactly my problem – petaire Jan 21 '18 at 10:31
  • Be nice I'm only trying to help and I have no idea of your knowledge, what you think as obvious (me too) some people asking questions have no idea of. The issue was confused by referring to actual bounds. I see you solved it by fixing the LaunchScreen. Does that now show in the black areas? Also where does it show that bounds for every simulator by which I mean where are you checking it? – Upholder Of Truth Jan 21 '18 at 10:33

1 Answers1

3

The possible screen sizes are defined in iOS via the launch screen image. So you should either have created an image for each resolution or use a storyboard for that.

clemens
  • 16,716
  • 11
  • 50
  • 65
  • Yup, that was the issue, I've removed the LaunchScreen storyboard, and that caused the crash. Thanks ! – petaire Jan 21 '18 at 10:27
  • Just in case anyone else sees this if you don't want to use a launch screen storyboard you can also switch over to providing launch images instead. You have to do one or the other for the correct main screen bounds to be set. – Upholder Of Truth Jan 21 '18 at 10:47
  • @UpholderOfTruth Keep in mind that using launch images prevents the ability of the app to support multitasking on an iPad. For that you must use a launch screen storyboard. – rmaddy Jan 21 '18 at 18:21
  • Good point it does indeed but sometimes that is what you want. Personally unless there is a good reason I go the launch screen storyboard but it's best to know both methods. – Upholder Of Truth Jan 21 '18 at 18:23