宽度未拉伸以满足使用 AutoLayout 的约束

Width is not streching to meet the contraint using AutoLayout

所以我试图让我的设计在 iphone 6 上伸展到全宽,但由于某种原因,约束没有按照我的意愿进行。

下箭头的宽度比 10 大很多。

可能是什么问题?您是否需要我提供其他信息来调试问题?

超级视图是一个水平滚动被禁用的 ScrollView,因为它的价值...

UIScrollView 中使用 AutoLayout 时,滚动视图的 contentSize 是根据在滚动视图中添加的约束计算的。

从表面上看,您希望滚动视图的 contentSize.width 等于其父视图的 bounds.size.width

为此,您只需向滚动视图添加一个约束,指示它限制其宽度等于其父视图的宽度。

在代码中,它会是这样的:

[NSLayoutConstraint constraintWithItem:self.scrollView attribute:NSLayoutAttributeWidth relatedBy:NSLayoutRelationEqual toItem:self.view attribute:NSLayoutAttributeWidth multiplier:1.0 constant:0.0];

或者在 Interface Builder 中,您可以简单地按住 Ctrl 键,然后从滚动视图拖动到其父视图以添加 Equal Widths约束。