Problem setting autosizing in interface builder

我的梦境 提交于 2019-12-09 04:35:43

问题


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.


回答1:


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:


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:

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

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




回答3:


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


来源:https://stackoverflow.com/questions/3997967/problem-setting-autosizing-in-interface-builder

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!