首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >XCode6 NSSplitViewController持有优先事项与canCollapse无效

XCode6 NSSplitViewController持有优先事项与canCollapse无效
EN

Stack Overflow用户
提问于 2014-10-31 09:21:22
回答 1查看 3.1K关注 0票数 2

我希望有人能帮我解决这个问题。

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

它不能从接口构建器中完成,尽管这个视频显示的不是:https://www.youtube.com/watch?v=ZIIuPo4F6tQ

我只能使splitview项在代码中具有最小的宽度,但这差不多就是了。我测试了Swift和Objective实现,但没有成功。

这就是我用斯威夫特写的:

代码语言:javascript
复制
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
}

这些都不起作用。我甚至试着把调用转移到函数底部的超级程序,结果却没有什么好运气。

我想知道是有人找到了解决方案,还是我做错了什么?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2014-11-19 22:09:58

  • 使NSSplitViewController成为NSSplitView的委托:例如,在IB中,将NSSplitView的委托出口连接到控制器。(在IB模板中,这似乎不像人们所期望的那样自动连接.)
  • 与编码不同,您可以使用IB来更改NSSplitViewItem的保持优先级(例如,其中一个是249,另一个是250)。
  • 在这里,您也可以检查“可以崩溃”等。
  • 我还使用IB设置子视图的最小大小约束。

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

此基本设置按预期工作,不需要特定的编码或覆盖。(OS X Storyboard应用程序,Swift,Xcode 6.1)

票数 11
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/26671160

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档