SnapKit / Masonry

Harness the power of AutoLayout NSLayoutConstraints with a simplified, chainable and expressive syntax. Supports iOS and OSX Auto Layout
MIT License
18.06k stars 3.15k forks source link

两个view水平排列时怎么让左view的左边距等于右view的右边距 #527

Closed jiutianhuanpei closed 6 years ago

jiutianhuanpei commented 6 years ago

Issue Description

这是我的需求:

水平排列的两个视图,v1 及 v2

v1的宽为50,v2的宽为100,它们的间距为5,我需要v1的左边距x 等于 v2的右边距y

可能在项目之中 v2的宽可能需要自适应,所以不能用计算的方法先算出 x 的值 。

Daniate commented 6 years ago

You should add placeholder views at the position of x & y

jiutianhuanpei commented 6 years ago

@Daniate Can you write a sample code ?

Daniate commented 6 years ago

@jiutianhuanpei Are you a beginner?

Plan 1

2018-08-29 7 09 14

Wrap v1&v2,you should add some constraints. I think you can.

Plan 2

2018-08-29 7 09 19

I think you can understand these figures.

jiutianhuanpei commented 6 years ago

Thanks ,I see what you mean

Wenjie-Qin commented 5 years ago

只有这两种方法吗?这两种方法都要多创建出来视图控件作为辅助,没有其他更好的方法吗?

Daniate commented 5 years ago

加入辅助视图,是苹果官方给的解决方案,在AutoLayout早期相关的文档里,有相关描述,不过现在无法找到相关文档了,但苹果给了示例项目Auto-Layout-Cookbook,里面有个EqualWhiteSpace的示例,用的就是辅助视图,苹果把它们称作dummy views