此问题与我之前询问过如何添加在单独的xib here中定义的视图的问题有关。我仍然在努力解决这个问题,现在我得到了这个特定于布局的错误,所以我觉得最好问一个新问题。
我有2个xib,并且我试图将xib1中的视图插入到xib2上的NSView占位符中,并且我希望在调整视图大小时调整xib1中的视图的大小。 / p>
这是我尝试设置左/右约束的代码。
let placeholder: NSView = self.m_viewPlaceHolder;
let insert: NSView = UserView01().view;
insert.frame = NSRect(x: 0, y: 0, width: placeholder.frame.width, height: placeholder.frame.height);
placeholder.addSubview(insert);
NSUserDefaults.standardUserDefaults().setBool(true, forKey: "NSConstraintBasedLayoutVisualizeMutuallyExclusiveConstraints");
let hor = NSLayoutConstraint.constraintsWithVisualFormat("H:|-[view]-|", options: NSLayoutFormatOptions(rawValue: 0), metrics: nil, views: ["view" : insert]);
NSLayoutConstraint.activateConstraints(hor);
这是我在跟踪中看到的错误
2016-01-12 20:49:09.307 SubView01[9240:308241] Unable to simultaneously satisfy constraints:
(
"<NSLayoutConstraint:0x608000087800 H:|-(NSSpace(20))-[NSView:0x608000120500] (Names: '|':NSView:0x6080001206e0 )>",
"<NSAutoresizingMaskLayoutConstraint:0x6000000842e0 h=--& v=&-- H:|-(0)-[NSView:0x608000120500] (Names: '|':NSView:0x6080001206e0 )>"
)
Will attempt to recover by breaking constraint
<NSLayoutConstraint:0x608000087800 H:|-(NSSpace(20))-[NSView:0x608000120500] (Names: '|':NSView:0x6080001206e0 )>
Set the NSUserDefault NSConstraintBasedLayoutVisualizeMutuallyExclusiveConstraints to YES to have -[NSWindow visualizeConstraints:] automatically called when this happens. And/or, break on objc_exception_throw to catch this in the debugger.
2016-01-12 21:00:19.409 SubView01[9240:308241] Clicked on overlapping visualized constraints: (
"<NSLayoutConstraint:0x608000087800 H:|-(NSSpace(20))-[NSView:0x608000120500] (Names: '|':NSView:0x6080001206e0 )> (Actual Distance - pixels):0",
"<NSAutoresizingMaskLayoutConstraint:0x6000000842e0 h=--& v=&-- H:|-(0)-[NSView:0x608000120500] (Names: '|':NSView:0x6080001206e0 )> (Actual Distance - pixels):0"
)
我在设计器中添加的唯一约束是左/上/右/下0占位符到主窗口的0像素约束,以及标签上的用户视图。
答案 0 :(得分:1)
视图的隐式自动调整遮罩存在冲突。
两个选项:
通过关闭AutoLayout,更改掩码并再次启用AutoLayout或取消选中translates autoresizing mask into constraints
(如果可用),将掩码设置为适合Interface Builder的内容。
以编程方式执行相同操作设置掩码
view.autoresizingMask = [...]
或停用translatesAutoresizingMaskIntoConstraints
view.translatesAutoresizingMaskIntoConstraints = false