视图控制器调整大小

发布于 2024-12-28 16:45:04 字数 100 浏览 2 评论 0原文

如何改变ViewController的大小?我正在制作一个简单的应用程序,它故意使用两个视图,一个用于水平视图,一个用于垂直视图。我试图调整它的检查器视图大小,但字段是灰色的且不可更改。

How to change sizes of ViewController? I'm making simple app which uses deliberately two views, one for horizontal and one for vertical view. I was trying to resize it inspector-view but the fields are gray and unchangeable.

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

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

发布评论

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

评论(1

清君侧 2025-01-04 16:45:04

UIViewController 不负责设置其根视图的大小。预计视图控制器的视图的父级(窗口或某些容器视图控制器)将调整视图的大小以填充窗口、适合选项卡栏上方或以其他方式适当定位。因此,Interface Builder 不允许您在该视图上设置误导性的框架值。

要根据方向交换视图,我建议向根视图添加两个子视图,并为每个方向使用一个子视图。即使这样,您在 Interface Builder 中为它们设置的大小也有些误导;您将能够设置您想要的尺寸,更重要的是,您应该设置它们的自动调整大小属性,以便它们扩展/收缩以填充其父视图。这样,当状态栏的高度发生变化或添加容器视图控制器时,您的布局就不会中断。

UIViewControllers are not responsible for setting the size of their root view. It is expected that the parent of the view controller's view (either the window or some container view controller) will adjust the view's size to fill the window, fit above the tab bar, or otherwise be appropriately positioned. Interface Builder therefore doesn't allow you to set misleading frame values on that view.

To swap view based on orientation I suggest adding two sub-views to your root view and using one for each orientation. Even then the size you set for them in Interface Builder is somewhat misleading; you'll be able to set the sizes you want more importantly you should set their autoresizing properties such that they expand/shrink to fill their parent view. That way your layout won't break when the height of the status bar changes or you add a container view controller.

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