在界面生成器中设置自动调整大小时出现问题

发布于 2024-09-28 12:05:05 字数 443 浏览 10 评论 0原文

我有两个 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.

Interface Builder, Autoresizing Mask

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

夜巴黎 2024-10-05 12:05:05

我以前遇到过这个问题,这非常令人沮丧。事实证明,当您打开模拟用户界面元素时,您将无法根据需要更改支柱和弹簧。

转到“属性”选项卡 (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.

碍人泪离人颜 2024-10-05 12:05:05

我有一个简化的答案:

  1. 转到IB
  2. 单击“ViewController”
  3. 转到“属性检查器”
  4. 将“大小”更改为“自由形式”(“推断”之外的其他内容)

您所拥有的是这样的:

在此处输入图像描述

将“尺寸”更改为“自由形式”&立即尝试!

在此处输入图像描述

现在,它可以工作了!返回&设置自动调整大小蒙版后,将其更改为“推断”。

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.

日久见人心 2024-10-05 12:05:05

打开 Main.storyboard 作为源(不要忘记,它只是一个 XML 文件)并用以下行替换视图中的“autoresizingMask”标签:

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

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"/>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文