如何指定我希望 UI 元素在 Interface Builder 中进行方向更改的位置?

发布于 2024-10-08 04:25:40 字数 319 浏览 3 评论 0原文

好吧,我知道这是一个新手问题,但因为我是新手,所以没关系!我认为我正在努力让IB的迎新活动变得友好,但我遇到了一些困难。

当然,我让所有东西在纵向模式下看起来都不错,但是当我进入横向模式时(通过点击右上角的箭头),一切都变得一团糟。

现在,由于视图的布局方式,我需要在纵向中沿图像视图的底部对齐 3 个按钮,然后在横向中,这三个按钮需要沿右侧对称对齐。

在尺寸检查器中摆弄那些红色箭头的组合并没有给我带来我正在寻求的结果。是否可以在 IB 中以一种方向以一种方式设置按钮,然后在更改时将它们设置为完全不同的?

我到处寻找有用的 IB 教程,但没有找到任何东西。

Ok so I know this is a bit of a newbie question, but being that I am a newbie its ok! I have a view that I am trying to make orientation friendly in IB, and I am having some difficulties.

I have everything looking nice in portrait of course, but then when I go to landscape mode (by hitting that arrow in the top-right corner) everything gets all messed up.

Now, because of the way the view is laid out, I need to align 3 buttons along the bottom of an image view in portrait, and then in landscape, those three buttons need to be symmetrically aligned along the right side.

No combination of fiddling with those red arrows in the size inspector are rewarding me the results I am seeking. Is it possible to set up the buttons one way in one orientation in IB, and then on change, set them completely different?

I have looked all around for a useful IB tutorial, but haven't been able to find anything.

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

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

发布评论

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

评论(2

十年不长 2024-10-15 04:25:40

我知道您想在 IB 中执行此操作,但如果您愿意以编程方式尝试,那么您可以非常轻松地移动内容。对于您的按钮,只需实现如下所示的 setCenter 方法:

[myButton setCenter:CGPointMake(xCenter,yCenter)];

否则,如果您想使用 IB,请使用“自动调整大小”选项。箭头将拉伸或压缩宽度和高度,条形 (|-|) 保留与顶部和底部的距离。如果连续有三个按钮,则可以固定左侧按钮的左侧距离、右侧按钮的右侧距离以及中间按钮的两者/两者都不固定。类似的东西可能会起作用。

第三个选项是创建一个新视图,将其称为横向视图或其他视图,方法是将 UIView 从库中拖到具有文件所有者、第一响应者、视图等的窗口中。然后将其定向为横向,复制所有 UI 对象,按照你喜欢的方式布局它们,当你旋转时,用landscapeView替换当前视图。我发现的问题(众多问题之一)是您必须重新连接所有内容,并为标签等使用不同的 IBOutlet。时间

I know you want to do this in IB, but if you're willing to try it programmatically, then you can move things around pretty easily. For your buttons, just implement the setCenter method like this:

[myButton setCenter:CGPointMake(xCenter,yCenter)];

Otherwise, if you want to use the IB, use the Autosizing options. The arrows will stretch or compress the width and height, and the bars (|-|) preserve distances from the top and bottom. If you have three buttons in a row, you can fix the left distance for the left button, the right distance for the right button and both/neither for the center button. Something like that may work.

The third option is to make a new view, call it landscapeView or something, by dragging a UIView from the library to the window with File's Owner, First Responder, View, etc. Then orient that to landscape, copy over all your UI objects, lay them out as you like, and when you rotate, replace the current view with landscapeView. The problem with this that I've found (one of many) is that you have to reconnect everything and have different IBOutlets for the labels and whatnot. T

秋心╮凉 2024-10-15 04:25:40

使用 IB 的自动调整大小功能只能做这么多。 PengOne 在他的第二段中很好地描述了它们。如果它们还不够,您必须以编程方式移动元素。请参阅 响应方向变化。否则,您可以使用完全不同的视图,正如 PengOne 所提到的。

Using IB's autosizing features can only do so much. PengOne does a good job of describing them in his second paragraph. If they are not enough, you have to move the elements programmatically. See Responding to Orientation Changes. Otherwise, you can just use a completely different view, again as mentioned by PengOne.

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