1

我正在尝试构建一个相当简单的视图。我有一个水平工具栏 (toolbarView) 和一个底部重音线 (bottomAccent) 运行视图的整个宽度。我还有两个侧边栏和屏幕左侧旁边的垂直重音。

如果我有一个侧边栏(注释掉 sidebarView2),生活很美好,一切看起来都恰到好处。一旦我添加了 sidebarview2,我就会得到这些有趣的错误。我不完全确定为什么或我做错了什么。我希望我的约束基本上将侧边栏的空间分成两半,并用侧边栏视图之一填充每一半。我在这里缺少什么?

Unable to simultaneously satisfy constraints:
(
    "<NSLayoutConstraint:0x7feefc3121e0 V:|-(8)-[NSTextField:0x7feefa4404e0]   (Names: '|':BGView:0x7feefa440290 )>",
    "<NSLayoutConstraint:0x7feefc312230 V:[NSTextField:0x7feefa4404e0]-(6)-[BGView:0x7feefa4408c0]>",
    "<NSLayoutConstraint:0x7feefc3122b0 V:[BGView:0x7feefa4408c0(1)]>",
    "<NSLayoutConstraint:0x7feefc312300 V:[BGView:0x7feefa4408c0]-(4)-[NSScrollView:0x7feefa440ba0]>",
    "<NSLayoutConstraint:0x7feefc312350 V:[NSScrollView:0x7feefa440ba0]-(0)-|   (Names: '|':BGView:0x7feefa440290 )>",
    "<NSLayoutConstraint:0x7feefc313250 V:[BGView:0x7feefa440290]-(0)-[BGView:0x7feefa440290]>"
)

我的代码:

- (void)loadView {
    NSView *rootView = [[NSView alloc] init];

    NSView *toolbarView = _toolbarViewController.view;
    [toolbarView setTranslatesAutoresizingMaskIntoConstraints:NO];
    [rootView addSubview:toolbarView];

    NSView *sidebarView = _titledScrollViewController.view;
    [sidebarView setTranslatesAutoresizingMaskIntoConstraints:NO];
    [rootView addSubview:sidebarView];

    NSView *sidebarView2 = _titledScrollViewController.view;
    [sidebarView2 setTranslatesAutoresizingMaskIntoConstraints:NO];
    [rootView addSubview:sidebarView2];

    BGView *horizontalSpacerSidebar = [[BGView alloc] initWithBackgroundColor:[NSColor colorWithDeviceRed:0.391 green:0.391 blue:0.43 alpha:1.0]];
    [horizontalSpacerSidebar setTranslatesAutoresizingMaskIntoConstraints:NO];
    [rootView addSubview:horizontalSpacerSidebar];

    BGView *bottomAccent = [[BGView alloc] initWithBackgroundColor:[NSColor colorWithDeviceRed:0.223 green:0.77 blue:0.93 alpha:1.0]];
    [bottomAccent setTranslatesAutoresizingMaskIntoConstraints:NO];
    [rootView addSubview:bottomAccent];

    NSDictionary *views = NSDictionaryOfVariableBindings(toolbarView, bottomAccent, sidebarView, sidebarView2, horizontalSpacerSidebar);

    [rootView addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"H:|[toolbarView]|" options:0 metrics:nil views:views]];
    [rootView addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"H:|[sidebarView(==200)][horizontalSpacerSidebar(==1)]" options:0 metrics:nil views:views]];
    [rootView addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"H:|[sidebarView2(==200)][horizontalSpacerSidebar(==1)]" options:0 metrics:nil views:views]];
    [rootView addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"H:|[bottomAccent]|" options:0 metrics:nil views:views]];
    [rootView addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:|[toolbarView(==53)][sidebarView][sidebarView2][bottomAccent(==3)]|" options:0 metrics:nil views:views]];
    [rootView addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:|[toolbarView(==53)][horizontalSpacerSidebar][bottomAccent(==3)]|" options:0 metrics:nil views:views]];

    self.view = rootView;
}
4

0 回答 0