IOS controller shift after rotation

I am working on an iOS app. My application delegate loads my view controller into the window and displays it correctly, with one caveat: the views on my view controller are not too far along the Y axis, and the status bar closes my top view. I changed my controller XIB controller file to accommodate, so now all my views start at 20 pixels along the Y axis. Everything looks fine on boot. When I rotate, my views are 20 pixels lower than they should be (due to my layout change to accommodate the first load). I am wondering how best to handle positioning in the view controller to handle the height of the status bar.

+4
source share
2 answers

I ran into this problem without turning the view directly / programmatically into a window. Instead, I create a RootViewController that sits and aligns correctly in both orientations and has all other views inside the RootViewController.

The reason for this is that the application window is always full screen (including the top status bar). If you try to fill the Window, you have to deal and compensate for the status bar and other chrome. It makes this easier if you manage all the views in the root view.

+1
source

Your decision depends on how you created the project.

If you used a view-based application template when creating a project, then you will have a view controller in MainWindow.xib. The controller of your view should work correctly both initially (at startup) and after turning the devices, provided that you have the status bar attribute enabled (i.e., gray or black is selected) for your view controller in this NIB.

If you used the Window-based Application template when creating the project, you need to add the following line of code to the delegate of your application didFinishLaunchingWithOptions:

myViewController.view.frame = window.screen.applicationFrame; 

which is somehow magically configured correctly.

0
source

All Articles