【发布时间】:2018-01-31 09:08:37
【问题描述】:
【问题讨论】:
-
添加你使用的代码
-
横向模式下你检查按钮的宽度了吗?
-
你需要添加你用于按钮背景的代码
-
横向模式下如何查看宽度?
-
另外......如何准确地实现代码而不会出现任何错误:)
【问题讨论】:
在您的情况下,问题是按钮被按下height = 0,因为您对按钮有这两个约束:
clickHere.centerYAnchor.constraint(equalTo: self.view.centerYAnchor)
和
clickHere.bottomAnchor.constraint(equalTo: self.bottomLayoutGuide.topAnchor, constant: 304)
在横向中,按钮的 centerY 比 304 + buttonHeight 更靠近底部,因此自动布局将按钮按到 height = 0 以尽可能接近满足约束。由于按钮的高度由按钮的固有大小设置,因此其优先级低于约束的优先级。
在您的情况下,解决方案非常简单,只需删除第二个约束:
clickHere.bottomAnchor.constraint(equalTo: self.bottomLayoutGuide.topAnchor, constant: 304)
在您的故事板屏幕截图中,它位于约束列表的底部,其名称为
底部布局 Guide.top = 点击此处.bottom + 304
【讨论】: