您好我设计了一个使用 AutoLayout 约束的 XIB 来显示两行按钮,每行三个按钮,如屏幕截图所示(我将在获得满意的布局后将按钮放在红色 UIViews 中):
到目前为止一切顺利,在纵向模式下,如上图所示,按钮看起来不错。但是,当我旋转到横向时,标题(蓝色)和父视图(灰色)会调整大小并正确显示,但红色按钮视图会消失(见下文)。
设置约束以使其正常工作的最佳方法是什么?我遵循了 Ray Wenderlich 教程并使用了他在示例中使用的相同 Editor\Pin]Vertical Spacing 和 Editor\Pin\Horizontal 间距: 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.
我对此束手无策,所以这个博学团体的任何帮助将不胜感激......!