2

您好我设计了一个使用 AutoLayout 约束的 XIB 来显示两行按钮,每行三个按钮,如屏幕截图所示(我将在获得满意的布局后将按钮放在红色 UIViews 中):

纵向模式自动布局

到目前为止一切顺利,在纵向模式下,如上图所示,按钮看起来不错。但是,当我旋转到横向时,标题(蓝色)和父视图(灰色)会调整大小并正确显示,但红色按钮视图会消失(见下文)。

在此处输入图像描述

设置约束以使其正常工作的最佳方法是什么?我遵循了 Ray Wenderlich 教程并使用了他在示例中使用的相同 Editor\Pin]Vertical Spacing 和 Editor\Pin\Horizo​​ntal 间距: Ray Wenderlich 教程

我也得到了很多约束错误,如下所示:

        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) 
(
    "<NSLayoutConstraint:0x859abe0 UIView:0x85a8fb0.height == UIView:0x85a8e60.height>",
    "<NSLayoutConstraint:0x859ab60 V:[UIView:0x85a8fb0]-(114)-|   (Names: '|':UIView:0x85a8170 )>",
    "<NSLayoutConstraint:0x859ab20 V:|-(424)-[UIView:0x85a8fb0]   (Names: '|':UIView:0x85a8170 )>",
    "<NSLayoutConstraint:0x85a3430 V:|-(150)-[UIView:0x85a8170]   (Names: '|':UIView:0x85a8da0 )>",
    "<NSLayoutConstraint:0x85a33b0 V:[UIView:0x85a8170]-(NSSpace(20))-|   (Names: '|':UIView:0x85a8da0 )>",
    "<NSAutoresizingMaskLayoutConstraint:0x75ac610 h=--& v=--& V:[UIView:0x85a8da0(704)]>"
)

Will attempt to recover by breaking constraint 
<NSLayoutConstraint:0x859ab60 V:[UIView:0x85a8fb0]-(114)-|   (Names: '|':UIView:0x85a8170 )>

Break on objc_exception_throw to catch this in the debugger.
The methods in the UIConstraintBasedLayoutDebugging category on UIView listed in <UIKit/UIView.h> may also be helpful.

我对此束手无策,所以这个博学团体的任何帮助将不胜感激......!

4

1 回答 1

2

该错误意味着您有冲突的约束。试着让它工作一排。

  1. 将每个具有垂直间距的红色框固定到蓝色标题框
  2. 将带有前导空格的左侧红色框固定到超级视图
  3. 将带有尾随空格的右侧红色框固定到超级视图
  4. 设置中心红框左右水平间距
  5. 固定高度
  6. 选择所有三个红色框并将它们设置为具有相等的宽度(宽度相等)
  7. 删除 IB 添加的任何无关约束
  8. 在设备上测试。(我有模拟风景/肖像)在界面构建器中有时会改变约束。9 它应该看起来像所附的图像在此处输入图像描述
于 2013-02-20T22:40:01.893 回答