约束在横向方向上没有按预期工作

Constraints are not working as expected in landscape orientation

我使用自动布局测试非常简单的布局,只使用情节提要(没有任何代码)

我删除了 Button 对象 wAny、hAny,然后将大小 class 切换为 wCompact、hAny

并添加约束 'Center Horizontally in Container' & 'Top Space to Top layout guide'.

接下来我将大小 class 切换为 wAny、hCompact 并添加约束 'Center Vertically in Container' & 'Trailling space to Container Margin' 和宽度、高度约束

这就是我添加的所有约束,故事板中没有警告和错误。

我希望按钮在纵向上居中,在横向上居中。

纵向通常是 运行,但是当我使用错误日志更改方向时,预览和模拟器显示错误的结果。

像这样

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 translatesAutoresizingMaskIntoConstraints) 
(
    "\<_UILayoutSupportConstraint:0x7a065db0 V:[_UILayoutGuide:0x7a067440(0)]>",
    "<_UILayoutSupportConstraint:0x7a068010 V:|-(0)-[_UILayoutGuide:0x7a067440]   (Names: '|':UIView:0x7a0661d0 )>",
    "<NSLayoutConstraint:0x7a0680b0 V:[_UILayoutGuide:0x7a067440]-(20)-[UIButton:0x7a066740'Button']>",
    "<NSLayoutConstraint:0x7a06d9e0 'UIView-Encapsulated-Layout-Height' V:[UIView:0x7a0661d0(320)]>",
    "<NSLayoutConstraint:0x7a068050 UIView:0x7a0661d0.centerY == UIButton:0x7a066740'Button'.centerY>",
    "<NSLayoutConstraint:0x7a0680e0 V:[UIButton:0x7a066740'Button'(30)]>"
)

Will attempt to recover by breaking constraint "<NSLayoutConstraint:0x7a0680e0 V:[UIButton:0x7a066740'Button'(30)]>

按钮填充其容器视图的宽度和高度。

我不知道我做错了什么?

我是否遗漏了有关自动布局(带方向)的重要信息?

请帮助我

(抱歉我的英语不好。我的母语不是英语-)

你的问题是 wCompact|hAny 适用于纵向或横向的 iPhone。所以你最终会在景观中遇到冲突的约束,因为你的所有约束都适用。对于纵向的 iPhone,您应该使用 wCompact|hRegular