问题描述
我在建立X code 5的iOS应用,而我有麻烦添加布局约束。在第X code 4.x的,我只需要添加前/后/顶/底部的空格容器(上海华)任何UI元素。现在,我只有这个选项:
I am building an iOS app in Xcode 5, and I'm having trouble adding layout constraints. In Xcode 4.x, I could just add leading/trailing/top/bottom spaces to container (superview) to any UI element. Now, I only have this option:
我想补充一个底部空间,上海华约束到我的文本视图。它说:间距最近的邻居,但我不希望创建一个约束,以近邻,我在我的文本视图别的东西,我不希望创建与约束。如果在我的文本视图没有其他物体,它正确地增加了一个约束的容器。但是,如果我试图改变任何东西,一切都弄乱了:我需要到别的地方把所有的意见,然后添加约束,再加入移动另一观点回来。如果我添加文本视图和用户界面元素(按钮,在这种情况下),这是行不通的(之间的约束似乎一切正常:按钮具有制约上海华的底部,文本视图具有与垂直间距约束按钮,并且没有冲突的约束)。 UI元素在不同(3.5英寸)的屏幕显示方向显现出屏幕界。是否存在与Interface Builder中的一个bug,还是我失去了一些东西?当我能够正确设置好一切,我的控制似乎仍然出界,当我调整界面生成器屏幕,但在3.5英寸正确模拟器/设备上显示。什么是与X code 5?
I want to add a "bottom space to superview" constraint to my text view. It says "spacing to nearest neighbor", but I don't want to create a constraint to "nearest neighbor", I have something else under my text view, and I don't want to create a constraint with that. If there is no other object under my text view, it adds a constraint to the container correctly. But if I try to change anything, everything messes up: I need to move all the views somewhere else, then add the constraint, then add move the other views back. If I add a constraint between the text view and the UI element (a button, in this case), it doesn't work (everything seems correctly: button has a constraint to superview's bottom, and text view has a vertical spacing constraint with the button, and there are no conflicting constraints). The UI elements appear out of screen bounds in different (3.5 inch) screen orientations. Is there a bug with the Interface Builder, or am I missing something? When I could set everything up correctly, my controls still seem out of bounds when I resize the interface builder screens, but display correctly on simulator/device at 3.5 inches. What is the "best practice" of designing the UI with the new Interface Builder constraints in Xcode 5?
更新:我在与同一件事的另一个项目的一些更多的麻烦。我想完全按CTRL-拖我的控制,它说:上面的布局指南,以解决一个视图的顶级顶端布局指导,它正试图通过约-470至阿玲我的控制布局指南(底部而不是alinging我控制的顶部,它不作任何意义,因为控制应高度可变的屏幕布局本身(如定期和4英寸的iPhone,并在未来可能的其他布局..)点)。这是发生了什么事的截图:
UPDATE: I'm having some more trouble in another project with the same thing. I am trying to fix a view's top to the top layout guide exactly by CTRL-dragging my control to where it says "top layout guide", and it is trying to aling the bottom of my control to the layout guide (by about -470 points) instead of alinging the top of my control, which doesn't make any sense as the control should layout itself in variable height screens (e.g. regular and 4-inch iPhone, and the possible other layouts in the future..). Here is a screenshot of what's happening:
和我在约束得到这个:
我怎样才能让界面生成器对准的上方的视图顶端布局指南?
How can I make Interface Builder align the top of the view to the top layout guide?
更新2:我找到了一个解决方法。我第一次调整,以减小它的高度(所以它的顶部不会重叠或非常接近顶部的布局指南),然后我CTRL +将其拖到顶部布局指南。它似乎正常工作。我将它连接后,我再次调整我认为到所需的大小,选择更新约束
。它的工作原理,但它需要调整的观点,连接,重新调整和更新限制它仍然不是一个解决方案。
UPDATE 2: I've found a workaround. I first resize the view to decrease it's height (so the top of it will not overlap or be very close to the top layout guide) and THEN I CTRL+drag it to the top layout guide. It seems to work correctly. After I connect it, I resize my view again to the desired size and select Update Constraints
. It works, but it's still not a solution as it requires resizing the view, connecting, resizing again, and updating constraints.
推荐答案
要添加视图和它的上海华(如底部空间,上海华),您可以使用文档大纲(该界面的左侧部分之间的约束生成器)。
To add a constraint between a view and its' superview (like "bottom space to superview") you can use the Document Outline (The left part of the Interface Builder).
在文档大纲:
- 按住Ctrl键并拖动从视图中的上海华(反之亦然)。
- 选择您想(在这个例子中底部空间集装箱)添加的约束。
这篇关于间距约束加入上海华在X code 5的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!