xcode “添加新约束”复选框和字段被禁用
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/28377493/
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
"Add New Constraints" checkboxes and fields are disabled
提问by Andy in Boulder
I have a project I am upgrading from Xcode 4.6.3 to Xcode 6.1.1. I opened it in Xcode 6.1.1, and opened each .xib. The format of each .xib changed as expected. I want to attempt to use auto layout. Use Auto Layout is checked and so is Use Size Classes. I changed every appropriate object from Alignment Frame to be Alignment Rectangle.
我有一个要从 Xcode 4.6.3 升级到 Xcode 6.1.1 的项目。我在 Xcode 6.1.1 中打开它,并打开每个 .xib。每个 .xib 的格式都按预期更改。我想尝试使用自动布局。使用自动布局被选中,使用大小类也是如此。我将对齐框架中的每个合适的对象更改为对齐矩形。
For a while I couldn't add any constraints. Then after some trying I could add a few. See the screenshot.For the selected View, I cannot add a constraint. The Add New Constraints checkboxes and fields are disabled. Only Update Frames is available to be changed. I can't add an alignment constraint either. Ctrl-drag a line off the view does not add a constraint either. Notice the View height of 411. If I select another object, then select the View again the height will change to be the height of the parent tab bar less. If I keep doing that the height gets smaller and smaller, then Xcode crashes. How can I add a constraint to this view?
有一段时间我无法添加任何约束。然后经过一些尝试,我可以添加一些。看截图。对于选定的视图,我无法添加约束。添加新约束复选框和字段被禁用。只能更改更新帧。我也无法添加对齐约束。按住 Ctrl 键从视图中拖出一条线也不会添加约束。注意视图高度为 411。如果我选择另一个对象,然后再次选择视图,高度将更改为父标签栏的高度。如果我继续这样做,高度会越来越小,那么 Xcode 就会崩溃。如何向此视图添加约束?
The Tab Bar X, Y, Width, and Height are disabled. When I change the Height of the Assigned View Controller View, the Tab Bar Y changes to that value minus the Tab Bar Height of 49. When I select the View, again it's Height is now 49 less. Select the Tab Bar, it's Y is now 49 less. And so on. How do I set the dimensions of the Assigned View Controller View that will stick when I cannot add contraints?
标签栏 X、Y、宽度和高度被禁用。当我更改指定视图控制器视图的高度时,标签栏 Y 更改为该值减去标签栏高度 49。当我选择视图时,它的高度现在再次减少 49。选择 Tab Bar,它的 Y 现在少了 49。等等。当我无法添加约束时,如何设置分配的视图控制器视图的尺寸?
回答by mary alexis solis
I had the same issue. In my case, the view layout setting was set to Translate Mask Into Constraint
. I resolved it by changing it to Automatic
in Size Inspector
.
我遇到过同样的问题。就我而言,视图布局设置设置为Translate Mask Into Constraint
. 我通过将其更改为Automatic
in来解决它Size Inspector
。
回答by Andy in Boulder
Zev has the answer. You can't add constraints directly to the top-level view in a view controller.
泽夫给出了答案。您不能直接向视图控制器中的顶级视图添加约束。
In regards to the height of the View decreasing when selecting it, I started over from the original .xib making small changes and taking notes. When I checked "Use Auto Layout" and "User Size Classes", got alert the document will no longer be compatible with Xcode 5. Window frame size went from 320 568 to 600 600. ibExternalTranslatesAutoresizingMaskIntoConstraints went from 1 to 0. Other changes apparent as well. Adding constraints to objects contained in View one at a time I am getting good results. The behavior of the View height decreasing when I select it is gone.
关于视图在选择时降低的高度,我从原来的 .xib 重新开始,做了一些小改动并做笔记。当我检查“使用自动布局”和“用户大小类”时,收到警报,该文档将不再与 Xcode 5 兼容。窗口框架大小从 320 568 变为 600 600。ibExternalTranslatesAutoresizingMaskIntoConstraints 从 1 变为 0。其他变化显而易见好。一次向 View 中包含的对象添加约束,我得到了很好的结果。当我选择它时,视图高度降低的行为消失了。
回答by Prcela
Trick to enable constraints on the root view:
在根视图上启用约束的技巧:
- Inside the xib, drag a new view that will be sibling to the initial root view.
- Move the initial root view inside the sibling view. It will be able to have own constraints.
- Move the initial view back to be a root.
- Delete the empty sibling view.
- 在 xib 中,拖动一个与初始根视图同级的新视图。
- 将初始根视图移动到同级视图内。它将能够有自己的约束。
- 将初始视图移回根。
- 删除空的兄弟视图。