简体   繁体   English

Xcode约束

[英]Xcode Constraints

I'm having a problem with Xcode constraints. 我在Xcode约束方面有问题。 I'm laying out my entire layout, then selecting all the items and having Xcode 'fill in missing constraints'. 我正在布局整个布局,然后选择所有项目并让Xcode“填写缺少的约束”。 Now when I run the application in the simulator, labels and textboxes are NOT in the right places. 现在,当我在模拟器中运行应用程序时,标签和文本框不在正确的位置。 Sometimes not visible at all (appear to be off screen) 有时根本不可见(似乎不在屏幕上)

So are there any tips or tricks? 那么,有什么技巧或窍门吗? Should I layout 1 item at a time, set the constraints automatically then move to the next? 我是否应该一次布置1个项目,自动设置约束,然后移至下一个?

Don't trust XCode and 'fill in missing constraints' feature. 不要相信XCode并“填写缺失的约束”功能。 The best option is to set all constraints manually. 最好的选择是手动设置所有约束。 After some practice it's not that hard. 经过一些练习,这并不难。 You need to indicate X and Y coordinates and sometimes height/weight. 您需要指示X和Y坐标,有时还需要指示身高/体重。

I really don't advice setting constraints automatically. 我真的不建议自动设置约束。 It usually causes more problems than benefits. 它通常带来的问题多于收益。

Also check the console log at runtime. 还要在运行时检查控制台日志。 It may happen that there are conflicts between constraints and you need to fix it. 约束之间可能会发生冲突,您需要对其进行修复。

Check out the official guidlines 查看官方指南

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

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