请教一个 autolayout,总是提示约束冲突

2015-01-21 17:54:05 +08:00
 babyname

如图,我用 A 方法和 B 方法都提示冲突

前提: green view 必须有高度约束的 50

A布局中:
red 距离 super view top 10
green 距离 red view top 10
green 距离 super view bottom 20

此时提示 green 冲突了,不能同时满足 height 和 距离 super view bottom 20

B布局中:
red 距离 super view top 10
green 距离 red view top 10
purple 距离 green view top 0
purple 距离 super view bottom 20

此时还是提示冲突,怎么满足 green view 必须有高度约束呢?

这是一个 uitableviewcell 的布局,bottom也必须要有 Pin,否则自动检测高度无效。

相关代码
titleLabel.autoPinEdgeToSuperviewEdge(ALEdge.Top, withInset: verticalInsets)
titleLabel.autoPinEdgeToSuperviewEdge(ALEdge.Left, withInset: horizontalInsets)
titleLabel.autoPinEdgeToSuperviewEdge(ALEdge.Right, withInset: horizontalInsets)
dateLabel.autoPinEdgeToSuperviewEdge(ALEdge.Left, withInset: horizontalInsets)
dateLabel.autoPinEdge(ALEdge.Top, toEdge: ALEdge.Bottom, ofView: titleLabel, withOffset: verticalInsets / 2)
//
coverImage.autoPinEdge(ALEdge.Top, toEdge: ALEdge.Bottom, ofView: dateLabel, withOffset: verticalInsets)
coverImage.autoPinEdgeToSuperviewEdge(ALEdge.Left, withInset: horizontalInsets)
coverImage.autoPinEdgeToSuperviewEdge(ALEdge.Right, withInset: horizontalInsets)
coverImage.autoSetDimension(ALDimension.Height, toSize: screenWidth * 0.5597014925)
//
bottomGap.autoPinEdge(ALEdge.Top, toEdge: ALEdge.Bottom, ofView: coverImage)
bottomGap.autoPinEdgeToSuperviewEdge(ALEdge.Bottom, withInset: verticalInsets)

1950 次点击
所在节点    iDev
3 条回复
Shane
2015-01-21 21:38:29 +08:00
定义了top和bottom两个约束,肯定和固定height冲突啊,按你的意思,把top去掉不就可以了,另外,什么叫“自动检测高度无效”
cralison
2015-01-22 04:19:03 +08:00
是这样的,height不能同时设top和bottom,width不能同时设leading和trailing,因为这从逻辑上就说不通。
babyname
2015-01-22 09:11:16 +08:00
@cralison
@Shane
嗯,我height使用比例约束就好了

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/164230

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX