20

I have two viewControllers, one is a subclass of UIViewController (autoresizes correctly), the other one is a subclass of a subclass of UIViewController.
I did a layout in Interface Builder, I tested my code in the Simulator and everything works as expected. But if I rotate the device my views don't resize.
So I went back to Interface Builder and found out that I cannot change the Resizing property of the "root"-UIView. So I opened another file and the resizing property is fixed there, too. But it is set to resizing in both direction. This is the behavior I want.

How can I change the autoresizing of the top UIView so it does what I want?
There are not so many subviews that it is impossible to start again from scratch, but I don't want to do this.

Interface Builder, Autoresizing Mask

3 Answers 3

24

I ran into this before and it was incredibly frustrating. It turns out that when you have Simulated User Interface Elements turned on then you can't change the struts and springs like you want.

Go to Attributes tab (Cmd-1) and make sure that Status Bar, Top Bar, Bottom Bar, and Split View are all set to "Unspecified." Then go back to the Size tab (Cmd-3) and you'll be able to click the lines and changes your Struts and Springs. Then finally you can go back to Cmd-1 and turn those simulated elements back on.

2
  • You get a gold star for this. THANK YOU!
    – sean808080
    Dec 3, 2013 at 16:19
  • @lulian, That's because Xcode has changed the shortcut keys. Back in 2011, this was correct. Jan 14, 2015 at 20:40
13

I have a simplified answer:

  1. Goto IB
  2. Click on the 'ViewController'
  3. Goto 'Attributes Inspector'
  4. Change 'Size' to 'Freeform' (something other than 'Inferred')

What you have is this:

enter image description here

Change 'size' to 'freeform' & try now!

enter image description here

Now, it works! Go back & change it to 'Inferred' after you have set the Autoresizing masks.

0
0

Open Main.storyboard as source (do not forget, it is just an XML file) and replace "autoresizingMask" tag in the View with the following line:

<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.