xcode 在界面生成器中设计时自动布局视图调整大小的挫折

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/18369931/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-15 03:43:20  来源:igfitidea点击:

Auto Layout view resizing frustrations when designing in Interface Builder

xcodeinterface-builderautolayout

提问by Mario

Problem: UIView size is "locked" when designing with Auto Layout in IB

问题:在 IB 中使用 Auto Layout 进行设计时 UIView 大小被“锁定”

I've uploaded a 20 second video that illustrates my problem, but let me describe it. You may recognize the project: it's right out of Apple's WWDC 2012 "Introduction to Auto Layout." I've got a simple iPhone view in Interface Builder where I've already got a button and label along the bottom. The next step is to add a UIView. Here's where things get ugly.

我上传了一个 20 秒的视频来说明我的问题,但让我来描述一下。您可能会认出这个项目:它出自 Apple 的 WWDC 2012 “Introduction to Auto Layout”。我在 Interface Builder 中有一个简单的 iPhone 视图,我已经在底部有一个按钮和标签。下一步是添加一个 UIView。这就是事情变得丑陋的地方。

When I drag the UIView out of the palette in Interface Builder and onto the iPhone window, as soon as I let it go it seems to become lockedin to its starting size. I place it in the upper left corner, and I'd like to drag it horizontally to the right side of the window, and vertically to where it will be up against (minus the padding) the button and label along the bottom. But, when I try to resize it, I cannot. It's stuck on its original size!

当我将 UIView 从 Interface Builder 中的调色板拖到 iPhone 窗口上时,一旦我放开它,它似乎就被锁定到了它的起始大小。我把它放在左上角,我想把它水平拖到窗口的右侧,垂直拖到它靠着(减去填充)按钮和底部标签的地方。但是,当我尝试调整它的大小时,我不能。它卡在原来的尺寸上!

The video illustrating my problem is here:

说明我的问题的视频在这里:

http://www.youtube.com/watch?v=jsW4UwnCEkw

http://www.youtube.com/watch?v=jsW4UwnCEkw

You can see me grab the right edge of the view and try to pull it along to the right side of the window, but it won't expand. You can then see me move the entire view to the right side (it retains its size) and then try the opposite: grabbing the left side and trying to expand it so that it sizes up against the left side of the window. In both cases, the view is simply locked to its original size.

您可以看到我抓住视图的右边缘并尝试将其拉到窗口的右侧,但它不会展开。然后,您可以看到我将整个视图移到右侧(它保持其大小),然后尝试相反的操作:抓住左侧并尝试将其展开,使其大小与窗口左侧相对。在这两种情况下,视图都被简单地锁定为其原始大小。

What gives! Auto Layout in Interface Builder is just the most frustrating thing. How do I resize a view by dragging? Thanks!

是什么赋予了!Interface Builder 中的自动布局只是最令人沮丧的事情。如何通过拖动调整视图大小?谢谢!

(Note: Xcode 4.6.3.)

(注意:Xcode 4.6.3。)

回答by Rob

In IB, in the series of buttons in the lower right hand corner, click on the rightmost button:

在 IB 中,在右下角的一系列按钮中,单击最右侧的按钮:

rightmost button

最右边的按钮

When you do, you'll see a "When resizing Views Apply Constraints To..." pop-up menu:

当你这样做时,你会看到一个“当调整视图大小时应用约束到...”弹出菜单:

When resizing Views Apply Constraints To...

When resizing Views Apply Constraints To...

Make sure that "Siblings and Ancestors" is notchecked.

确保选中“兄弟姐妹和祖先” 。