gpt4 book ai didi

cocoa - NSSplitView 和自动布局

转载 作者:行者123 更新时间:2023-12-03 16:01:36 25 4
gpt4 key购买 nike

我应该如何在NSSplitView内使用自动布局约束 subview ?

我的NSSplitView subview 有 3 个 subview :topPane , tableContainerbottomPane我这样设置约束:

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设置它。

在分割 View 中使用自动布局的最佳方法是什么?有没有办法在没有NSSplitViewDelegate的情况下处理具有自动布局的分割 View subview 的最小/最大尺寸?

最佳答案

我发现如果我的窗口中有工具栏并通过任何此委托(delegate)方法控制分割 View ,则会出现此错误:

splitView:constrainMinCoordinate:ofSubviewAt:   
splitView:constrainMaxCoordinate:ofSubviewAt:
splitView:shouldAdjustSizeOfSubview:

在 windowDidLoad 中将工具栏附加到窗口中找到了解决方案。

关于cocoa - NSSplitView 和自动布局,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11262080/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com