在界面生成器中设置自动调整大小时出现问题
我有两个 viewController,一个是 UIViewController 的子类(正确自动调整大小),另一个是 UIViewController 子类的子类。
我在 Interface Builder 中进行了布局,在模拟器中测试了我的代码,一切都按预期工作。但如果我旋转设备,我的视图大小不会调整。
所以我回到 Interface Builder,发现我无法更改“root”UIView 的 Resizing 属性。所以我打开了另一个文件,调整大小属性也在那里固定。但它设置为在两个方向上调整大小。这就是我想要的行为。
如何更改顶部 UIView 的自动调整大小,使其达到我想要的效果?
子视图没有那么多,不可能从头开始,但我不想这样做。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我以前遇到过这个问题,这非常令人沮丧。事实证明,当您打开模拟用户界面元素时,您将无法根据需要更改支柱和弹簧。
转到“属性”选项卡 (Cmd-1),并确保状态栏、顶栏、底栏和拆分视图均设置为“未指定”。然后返回“大小”选项卡 (Cmd-3),您将能够单击线条并更改您的支柱和弹簧。最后,您可以返回 Cmd-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.
我有一个简化的答案:
您所拥有的是这样的:
将“尺寸”更改为“自由形式”&立即尝试!
现在,它可以工作了!返回&设置自动调整大小蒙版后,将其更改为“推断”。
I have a simplified answer:
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.
打开 Main.storyboard 作为源(不要忘记,它只是一个 XML 文件)并用以下行替换视图中的“autoresizingMask”标签:
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: