2

我希望有人可以帮助我解决这个问题。

无论我做什么,无论是通过 IB 还是在代码中,我都无法使新的 NSSplitViewController 及其项目可折叠或保持其优先级。

尽管此视频另有显示,但无法从界面构建器中完成:https ://www.youtube.com/watch?v=ZIIuPo4F6tQ

我只能使 splitview 项目在代码中具有最小宽度,但这就是它。我测试了 Swift 和 Objective-C 的实现都没有运气。

这是我用swift写的:

override func viewDidLoad() {
    super.viewDidLoad()

    // ---

    var left: NSSplitViewItem = self.splitViewItems[0] as NSSplitViewItem
    var right: NSSplitViewItem = self.splitViewItems[1] as NSSplitViewItem

    // ---

    // NOTE: these are not working properly in the interface builder for now

    self.view.addConstraint(NSLayoutConstraint(
        item: left.viewController.view,
        attribute: NSLayoutAttribute.Width,
        relatedBy: NSLayoutRelation.GreaterThanOrEqual,
        toItem: nil,
        attribute: NSLayoutAttribute.NotAnAttribute,
        multiplier: 0,
        constant: 200
    ))

    self.view.addConstraint(NSLayoutConstraint(
        item: right.viewController.view,
        attribute: NSLayoutAttribute.Width,
        relatedBy: NSLayoutRelation.GreaterThanOrEqual,
        toItem: nil,
        attribute: NSLayoutAttribute.NotAnAttribute,
        multiplier: 0,
        constant: 200
    ))

    // ---

    // NOTE: these are not working in the interface builder neither here but set anyway to demonstrate the problem

    left.canCollapse = true // has no effect
    right.canCollapse = true // has no effect

    // ---

    // NOTE: this is not working in the interface builder neither here but set anyway to demonstrate the problem

    right.holdingPriority = 1.0 // has no effect
}

这些都不起作用。我什至尝试将调用移动到函数底部的 super ,但运气不佳。

我想知道是否有人已经确定了解决方案,或者我做错了什么?

4

1 回答 1

11
  • 使 NSSplitViewController 成为 NSSplitView 的代表:例如,在 IB 中,将 NSSplitView 的代表出口连接到其控制器。(似乎这并没有像人们期望的那样在 IB 模板中自动连接......)
  • 您可以使用 IB 来更改 NSSplitViewItem 的持有优先级,而不是编码(例如,一个是 249,另一个是 250)。
  • 在这里您还可以检查“可以折叠”等。
  • 我还使用 IB 来设置子视图的最小尺寸约束。

(一个问题:折叠后,我无法用鼠标恢复折叠视图;这可能需要实现有效的矩形委托方法。更新:折叠时有效矩形不适用,所以我认为在代码中使用 NSSplitViewItem.collapsed 似乎成为解除折叠的唯一方法。这种行为与“经典”NSSplitView 不同......)

此基本设置按预期工作,无需特定编码或覆盖。(OS X 故事板应用程序、Swift、Xcode 6.1)

于 2014-11-19T22:09:58.900 回答