Xcode - 居中分段控件导致错误 (Swift)

Xcode - centering Segmented Control causes error (Swift)

我正在尝试将分段控件置于情节提要中的中心。我通过在容器边距中添加前导和尾随 space 的约束来做到这一点。

在我这样做之前,它在模拟器中看起来像这样:

下面是添加约束后我的 Storyboard 中的样子:

添加这些约束后,在模拟器中看起来像这样:

我在控制台中收到此错误:

Unable to simultaneously satisfy constraints. Probably at least one of the constraints in the following list is one you don't want. Try this: (1) look at each constraint and try to figure out which you don't expect; (2) find the code that added the unwanted constraint or constraints and fix it. (Note: If you're seeing NSAutoresizingMaskLayoutConstraints that you don't understand, refer to the documentation for the UIView property

将它 Center Horizontally 给超级视图。

出现此问题是因为情节提要中的场景是 600px 宽度,而您从两侧给它硬编码的边距,这就是它在小屏幕上被粉碎的原因。