【发布时间】:2012-06-29 12:48:24
【问题描述】:
我应该如何在NSSplitView 子视图中使用自动布局约束?
我的NSSplitView 子视图有 3 个子视图:topPane、tableContainer 和 bottomPane,我将约束设置如下:
NSDictionary* views = NSDictionaryOfVariableBindings(topPane, tableContainer, bottomPane);
for (NSView* view in [views allValues]) {
[view setTranslatesAutoresizingMaskIntoConstraints:NO];
}
[myView addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:|[topPane(34)][tableContainer][bottomPane(24)]|"
options:0
metrics:nil
views:views]];
[mySplitView addSubview:myView];
在控制台中得到了这个:
Unable to simultaneously satisfy constraints:
(
"<NSLayoutConstraint:0x7fd6c4b1f770 V:[NSScrollView:0x7fd6c4b234c0]-(0)-[CPane:0x7fd6c4b2fd10]>",
"<NSLayoutConstraint:0x7fd6c4b30910 V:[CPane:0x7fd6c4b2f870(34)]>",
"<NSLayoutConstraint:0x7fd6c4b30770 V:|-(0)-[CPane:0x7fd6c4b2f870] (Names: '|':NSView:0x7fd6c4b22e50 )>",
"<NSLayoutConstraint:0x7fd6c4b212f0 V:[CPane:0x7fd6c4b2fd10]-(0)-| (Names: '|':NSView:0x7fd6c4b22e50 )>",
"<NSLayoutConstraint:0x7fd6c4b2f910 V:[CPane:0x7fd6c4b2f870]-(0)-[NSScrollView:0x7fd6c4b234c0]>",
"<NSLayoutConstraint:0x7fd6c4b21290 V:[CPane:0x7fd6c4b2fd10(24)]>",
"<NSAutoresizingMaskLayoutConstraint:0x7fd6c3630430 h=--& v=--& V:[NSView:0x7fd6c4b22e50(0)]>"
)
Will attempt to recover by breaking constraint
<NSLayoutConstraint:0x7fd6c4b1f770 V:[NSScrollView:0x7fd6c4b234c0]-(0)-[CPane:0x7fd6c4b2fd10]>
我认为<NSAutoresizingMaskLayoutConstraint:0x7fd6c3630430 h=--& v=--& V:[NSView:0x7fd6c4b22e50(0)]> 会导致此问题,但我无法重置自动调整大小掩码,因为NSSplitView 设置了它。
在拆分视图中使用自动布局的最佳方式是什么?有没有办法在没有NSSplitViewDelegate的情况下处理具有自动布局的拆分视图子视图的最小/最大大小?
【问题讨论】:
-
这里有同样的问题。我将所有内容都放在 IB 中而不是以编程方式,但有类似的调试输出,包括
NSAutoresizingMaskLayoutConstraint。 -
这似乎在 10.8 下已修复,但正如您在 10.7 下所指出的那样已损坏。在 10.8 中,您可以在 Xcode 中设置拆分视图的内容视图的最小高度和宽度(无论如何是 4.5.2)。在 10.7 下无法执行此操作,并且在 10.8 中创建的应用程序在 10.7 中仍然无法正常工作
-
通常与 10.8+ 一起工作,但需要在大多数视图的子视图之间指定约束 - 不是 supre - 否则你会得到 Unable to 同时满足 错误..
标签: cocoa autoresizingmask nssplitview autolayout