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

标签 ios storyboard autolayout orientation constraints

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

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

并添加约束“在容器中水平居中”和“顶部空间到顶部布局指南”。

接下来我将大小类切换为 wAny、hCompact 并添加约束“在容器中垂直居中”和“尾随空间到容器边距”和宽度、高度约束

这就是我添加的所有约束, 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 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)]>

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

我不知道我做错了什么?

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

请帮帮我

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

最佳答案

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

关于ios - 约束在横向方向上没有按预期工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28324159/

相关文章:

swift - 如何以编程方式对我在容器 View 中调用的 ViewController 施加约束?

ios - 如何在这些 Uiimage View 中使用 Xcode 自动布局?

ios - Xcode 11 UILaunchImages 已被弃用,请改用启动 Storyboard 警告

ios - 桌面和 iPad 横向混合媒体查询

ios - UIView 是否可以使用有角度的边框?

c# - 暂停/恢复 WPF Storyboard

ios - iPhone 开发的 Git 管理

wpf - 如何让aTextBlock仅在ViewModel的依赖属性具有特定值时才闪烁?

ios - Xcode 6 为布局边距设置默认值或禁用它们

IOS - 我的数据使用不断返回数据