Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Portrait Layout is shown properly only after changing the orientation to Landscape and back to Portrait

I have a simple layout with multiple views and constraints to position and size them as I need. When I deploy the app to a simulator or device, the X, Y and Widths of all the views have the proper sizes. The Height on the other hand is always 0. All the views have proportional heights according to the super view.

Now, if I flip the orientation to Landscape and then back to portrait, everything shows up properly (the heights are no longer 0).

I've used the same logic with proportional heights previously, and I started seeing this problem with newly created view controllers after updating to Xcode 7.

EDIT You can get the .xib from: http://1drv.ms/1M81EUQ

like image 750
Ertay Shashko Avatar asked Oct 08 '15 11:10

Ertay Shashko


2 Answers

you have to Set different view update method call regarding the orientation changed if you use auto mask resizing or used autolayout to fix this .

like image 135
Chaudhary Ankit Deshwal Avatar answered Sep 23 '22 01:09

Chaudhary Ankit Deshwal


Your .xib was configured with Size Classes enabled, but your views and constraints were all configured to only be applied for Compact width, Regular height.

wC hR is Checked, Any Any is not

I went through and changed the views and constraints to apply to Any width, Any height, and this resolved the issue with landscape layouts.

Download the modified .xib file here

I recommend using Xcode 7's Preview Assistant View when working with Autolayout, as it will let you see multiple devices, in multiple orientations at the same time. This really helped in this case with showing that the layout was fine in portrait, but not in landscape.

This is what I saw in your .xib as you provided Preview of populated portrait but empty landscape views

And with the changes in my .xib Preview showing populated portrait and landscape

How could this have happened? One way is that you may have accidentally set the storyboard editor to a specific size class. If you see a blue border at the bottom of the editor, anything you add will be configured to be only installed for that specific size class. You can click on the size class shown to change it out to w Any h Any to return to the default mode.

Blue bar at the bottom of the storyboard editor

like image 34
savvyx4 Avatar answered Sep 20 '22 01:09

savvyx4