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

时间:2015-02-04 14:44:32

标签: ios storyboard autolayout orientation constraints

我测试非常简单的布局,只使用自动布局使用故事板(任何地方都没有代码)

我删除了Button对象wAny,hAny然后将size类切换为wCompact,hAny

并在容器中添加约束'水平中心'& “Top Top to Top布局指南”。

接下来我将尺寸类切换为wAny,hCompact并添加约束'Center in Vertical in Container'& “将空间转移到容器边距”和宽度,高度约束

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

我期望在画像中以顶部居中的按钮,在景观中居中。

肖像正常运行但预览和模拟器显示错误的结果,当我更改方向时出现错误日志。

像这样

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)]>

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

我无法弄清楚我做错了什么?

我是否遗漏了一些关于autolayout(带方向)的重要内容?

请帮帮我

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

1 个答案:

答案 0 :(得分:2)

您的问题是 wCompact | hAny 适用于纵向或横向的iPhone。因此,您最终会在横向上遇到冲突的约束,因为所有约束都适用。您应该以纵向使用 wCompact | hRegular 来制作iPhone。