XCode6 NSSplitViewController保持优先级并且canCollapse无法正常工作

Pas*_*ass 2 nssplitview autolayout swift xcode6

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

无论我做什么,无论是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
}
Run Code Online (Sandbox Code Playgroud)

这根本不起作用.我甚至尝试将调用移动到函数底部的super,没有太多运气.

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

iha*_*zed 11

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

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

此基本设置按预期工作,无需特定编码或覆盖.(OS X Storyboard App,Swift,Xcode 6.1)