Search code examples
swiftmacoscocoanssplitviewnssplitviewcontroller

Collapsing NSSplitViewItem does not call splitViewDidResizeSubviews


I have a class that inherits from NSSplitViewController and overrides the splitViewDidResizeSubviews function.

When I call collapse on a NSSplitViewItem inside the NSSplitViewController and I see the NSSplitViewItem visibly resize the splitViewDidResizeSubviews function isn't called.

If I resize the window the splitViewDidResizeSubviews function is called so I know it is implemented correctly.

Can I expect the splitViewDidResizeSubviews function to be called on a collapse and if so what might I be doing wrong?


Solution

  • Because collapsing splitViewItem doesn't resize its actual frame size but just toggling item's visibility. The splitViewItem holds the frame size if you just toggle isCollapsed status.

    (An exception is when item expands outward. Namely splitViewItem.collapseBehavior = .preferResizingSplitViewWithFixedSiblings. As I tested, it invokes splitViewDidResizeSubviews.)

    So for such usage I prefer to override another method of NSSplitViewController for instance:

    func splitView(_ splitView: NSSplitView, shouldCollapseSubview subview: NSView, forDoubleClickOnDividerAt dividerIndex: Int