开发者

Problem setting autosizing in interface builder

开发者 https://www.devze.com 2023-01-22 02:15 出处:网络
I have two viewControllers, one is a subclass of UIViewController (autoresizes correctly), the other one is a subclass of a subclass of UIViewController.

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.

Problem setting autosizing in interface builder


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.


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:

Problem setting autosizing in interface builder

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

Problem setting autosizing in interface builder

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


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"/>
0

精彩评论

暂无评论...
验证码 换一张
取 消