简体   繁体   English

遇到AutoLayout Xcode约束问题

[英]Having trouble with AutoLayout Xcode constraints

I have a somewhat complex layout that I want to make constraints for. 我有一个比较复杂的布局,我想对此加以限制。 就是这个。

Top three all need to be equidistant from each other and equal widths and heights. 前三者必须彼此等距且宽度和高度相等。 Bottom three need to be equal width and heights, and also equidistant from each other. 底部三个的宽度和高度必须相等,并且彼此之间等距。

How come Xcode doesn't have an equidistant margin option? Xcode为什么没有等距的边距选项? I can't create a specific margin constraint because it wont look correct on smaller devices. 我无法创建特定的边距约束,因为在较小的设备上它看起来不正确。 Nothing I do seems to create acceptable constraints. 我似乎没有做任何事情创建可接受的约束。

Thanks! 谢谢!

For top three you need to create 5 additional views, place them between this three views and set that they should have the same width. 对于前三个,您需要创建5个其他视图,将它们放置在这三个视图之间,并设置它们应具有相同的宽度。 One of them should have some constant width(than all other will get this width as well). 其中之一应具有一定的宽度(比其他所有宽度也要宽)。 Than bind them all by connecting leading and trealing constraints between them. 通过将它们之间的主导约束和交易约束联系起来,从而将它们绑定在一起。 Next thing to do, is to set your views width and height. 接下来要做的是设置视图的宽度和高度。 Margin that you need will be that five views that you placed before between them. 您需要的边距是在它们之间放置的五个视图。

The same thing you can do with your other views, just adding some views to make them as a margins. 您可以对其他视图执行相同操作,只需添加一些视图以使其成为空白即可。

Is it what you was searching for? 是您要找的东西吗? If not Pls describe your problem and I will try to solve it. 如果没有,请描述您的问题,我将尽力解决。

As @Dan said, UIStackView is your friend. 正如@Dan所说,UIStackView是您的朋友。 Put the top three in a horizontal stack view and the bottom three in a vertical one. 将顶部三个放置在水平堆栈视图中,将底部三个放置在垂直堆栈视图中。 Your other alternatives are to fiddle with the Multiplier on individual constraints, ie 0.0 0.333, 0.667. 您的其他选择是在各个约束条件下摆弄乘数,即0.0 0.333、0.667。 That would require a lot of work. 这将需要大量的工作。 One other choice, if you're willing to wait to use this in Xcode 8, is that Apple has reinstated the old springs and struts style of pre-Autolayout in Xcode 8, and allows you to use that as an alternative, and/or mixed in with auto layout in Xcode 8. Try the UIStackview first, though, it's the path of least resistance. 如果您愿意等待在Xcode 8中使用它,另一个选择是Apple恢复了Xcode 8中自动布局前的弹簧和支柱样式,并允许您将其用作替代,和/或在Xcode 8中混合了自动布局。但是,请首先尝试UIStackview,这是阻力最小的途径。

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

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