NSTabView和NSScrollView:无法同时满足约束

时间:2017-11-13 15:35:36

标签: swift xcode macos

该应用程序是使用Xcode和swift为macOS开发的,无需使用故事板即可以编程方式。

它由4个​​标签组成(原始,合成,融合,点数)。

工作正常,但每次更改标签时都会生成一个警报: [布局]无法同时满足约束条件:

每个选项卡包括NSViewController,NSView,NSScrollView,NSTableView。 例如,合成选项卡:

类GrandLivreSynthesView:NSView,NSTableViewDelegate,NSTableViewDataSource {

private var tableView: NSTableView = NSTableView()
private let scrolView: NSScrollView = NSScrollView()

self.scrolView.documentView = self.tableView
self.addsubview(scrolview)

4个标签的高度相同;不是宽度不同,可能是问题的根源。

我们在scrolView上只添加了两个约束:

func reloadCell () {

        let metricsDict: [String: CGFloat] = ["width": 1200, "height": 700]
        let viewsDict: [String: NSView] = ["scrolView": scrolView]

        self.removeConstraints(self.constraints)
        self.scrolView.translatesAutoresizingMaskIntoConstraints = false
        self.addConstraints(NSLayoutConstraint.constraints(withVisualFormat: "H:|[scrolView(width)]|", options: NSLayoutConstraint.FormatOptions.alignAllCenterX , metrics: metricsDict as [String : NSNumber]?, views: viewsDict))
        self.addConstraints(NSLayoutConstraint.constraints(withVisualFormat: "V:|[scrolView(height)]|", options: NSLayoutConstraint.FormatOptions.alignAllCenterX, metrics: metricsDict as [String : NSNumber]?, views: viewsDict))

        self.tableView.reloadData()
    }

每次我们从一个标签切换到另一个标签时,都会发送一个警报(不阻止应用程序):

2017-11-13 15:43:22.381025+0100 DAMOCLES[16696:4950184] [Layout] Unable to simultaneously satisfy constraints:
(
    "<NSLayoutConstraint:0x600000288660 H:|-(0)-[NSScrollView:0x6000001c6720]   (active, names: '|':DAMOCLES.GrandLivreRawView:0x600000183dc0 )>",
    "<NSLayoutConstraint:0x6000002886b0 NSScrollView:0x6000001c6720.width == 920   (active)>",
    "<NSLayoutConstraint:0x600000288700 H:[NSScrollView:0x6000001c6720]-(0)-|   (active, names: '|':DAMOCLES.GrandLivreRawView:0x600000183dc0 )>",
    "<NSAutoresizingMaskLayoutConstraint:0x600000288980 h=-&- v=-&- DAMOCLES.GrandLivreRawView:0x600000183dc0.minX == 0   (active, names: '|':NSTabView:0x1013d9020 )>",
    "<NSAutoresizingMaskLayoutConstraint:0x6000002889d0 h=-&- v=-&- H:[DAMOCLES.GrandLivreRawView:0x600000183dc0]-(0)-|   (active, names: '|':NSTabView:0x1013d9020 )>",
    "<NSAutoresizingMaskLayoutConstraint:0x600000485d70 h=-&- v=-&- DAMOCLES.GrandLivreSynthesView:0x6000001841d0.minX == 0   (active, names: '|':NSTabView:0x1013d9020 )>",
    "<NSAutoresizingMaskLayoutConstraint:0x600000485dc0 h=-&- v=-&- H:[DAMOCLES.GrandLivreSynthesView:0x6000001841d0]-(0)-|   (active, names: '|':NSTabView:0x1013d9020 )>",
    "<NSLayoutConstraint:0x60000029cbb0 H:|-(0)-[NSScrollView:0x6000001c6ae0]   (active, names: '|':DAMOCLES.GrandLivreSynthesView:0x6000001841d0 )>",
    "<NSLayoutConstraint:0x60000029cc50 H:[NSScrollView:0x6000001c6ae0]-(0)-|   (active, names: '|':DAMOCLES.GrandLivreSynthesView:0x6000001841d0 )>",
    "<NSLayoutConstraint:0x60000029cc00 NSScrollView:0x6000001c6ae0.width == 1200   (active)>"
)

Will attempt to recover by breaking constraint 
<NSLayoutConstraint:0x60000029cc50 H:[NSScrollView:0x6000001c6ae0]-(0)-|   (active, names: '|':DAMOCLES.GrandLivreSynthesView:0x6000001841d0 )>

Set the NSUserDefault NSConstraintBasedLayoutVisualizeMutuallyExclusiveConstraints to YES to have -[NSWindow visualizeConstraints:] automatically called when this happens.  And/or, set a symbolic breakpoint on LAYOUT_CONSTRAINTS_NOT_SATISFIABLE to catch this in the debugger.

我们不知道如何解读这个:&#34; h = - &amp; - v = - &amp; - &#34;。

如果我们改变最后一个约束H:[NSScrollView:0x6000001c6ae0] - (0) - |由H:[NSScrollView:0x6000001c6ae0] - (&gt; = 0) - |,警报消失,但窗口宽度没有变化。

我们尝试使用Debug view hierarchy进行分析,但我们无法确定缺少哪种约束。

我们还尝试在TabView上添加约束,但结果并不好。

我们真的可以使用一些帮助。 提前谢谢。

0 个答案:

没有答案