简体   繁体   English

Xcode 6.3情节提要自动布局约束

[英]Xcode 6.3 Storyboard Autolayout Constraints

This is my storyboard: 这是我的故事板:

故事堡

This is the iPad Simulator: 这是iPad模拟器:

iPad模拟器

For the constraints I go to the bottom right and click on the button that has a triangle with two extruding bars (it sort of looks like a star wars fighter with a triangle as the cockpit). 对于约束,我转到右下角,然后单击带有带有两个突出条的三角形的按钮(它看起来像是一个以三角形为驾驶舱的星球大战战士)。 I scroll down to the section that says all view in view controller I click on clear constraints. 我向下滚动到显示视图控制器中所有视图的部分,然后单击明确的约束。 Then I go back to the same button but this time I click add missing constraints. 然后,我回到同一按钮,但是这次单击添加缺少的约束。

Why is this happening? 为什么会这样呢? How can I fix it? 我该如何解决?

Adding missing constraints doesn't mean "add the constraint I think will look better in my project". 添加缺少的约束并不意味着“添加我认为在我的项目中看起来会更好的约束”。 Xcode adds some constraints to keep everything in place, but this may (or may not) be what you want. Xcode添加了一些约束以使所有内容保持不变,但这可能是(或可能不是)您想要的。

To paint a control in place without ambiguity your need at least 4 constraint, two on each axe (two for X, two for Y). 为了在不模糊的情况下绘制控件,您需要至少4个约束,每个轴上两个(两个X,Y两个)。 I recommend to clear all constraints, and start control by control, adding constraints. 我建议清除所有约束,并开始按控件进行控制,添加约束。

Some tips: 一些技巧:

  • you can set the constraints, then move a control, ask Xcode to refresh the constraints to the new position with the update Constraints option. 您可以设置约束,然后移动控件,要求Xcode使用update Constraints选项将约束刷新到新位置。 update frames option do the opposite: given a set of constraints, repaints your control in the right position. 更新框架选项执行相反的操作:给定一组约束,将控件重新绘制在正确的位置。

更新框架

  • Use the Assistant editor to split your Xcode view, so you can select Preview and have while designing your Storyboard and see how it looks. 使用助手编辑器拆分Xcode视图,以便在设计Storyboard时可以选择Preview并查看它的外观。 You can add different devices to see how it fits (little + button at the bottom) 您可以添加不同的设备以查看其适合情况(底部的小+按钮)

预习

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM