Collapse NSSplitView pane programatically

  • I am attempting to collapse an NSSplitView pane by setting the frame
    width (or height) to 0. When I shrink the frame, the pane looks like
    it's collapsed but the SplitView will still return false when I test
    it with isSubviewCollapsed. This is a problem when the user resizes
    the parent window, because the "collapsed" pane will start to creep
    outward again.

    There are a handful of posts on the cocoa-dev list where people are
    wrestling with NSSplitView trying to get it to do some fairly basic
    stuff, so I really wonder if what I'm attempting to do is even
    possible without subclassing.

    - .Dustin Wenz
  • Try RBSplitView instead: http://www.brockerhoff.net/src/rbs.html

    He's created an open source, versatile, easy to use, interface-
    builder compatible NSSplitView replacement.

    -Phil

    On Jan 31, 2006, at 1:30 AM, Dustin Wenz wrote:

    > I am attempting to collapse an NSSplitView pane by setting the
    > frame width (or height) to 0. When I shrink the frame, the pane
    > looks like it's collapsed but the SplitView will still return false
    > when I test it with isSubviewCollapsed. This is a problem when the
    > user resizes the parent window, because the "collapsed" pane will
    > start to creep outward again.
    >
    > There are a handful of posts on the cocoa-dev list where people are
    > wrestling with NSSplitView trying to get it to do some fairly basic
    > stuff, so I really wonder if what I'm attempting to do is even
    > possible without subclassing.
    >
    > - .Dustin Wenz
    > _______________________________________________
    > Do not post admin requests to the list. They will be ignored.
    > Cocoa-dev mailing list      (<Cocoa-dev...>)
    > Help/Unsubscribe/Update your Subscription:
    > http://lists.apple.com/mailman/options/cocoa-dev/<dev...>
    >
    > This email sent to <dev...>
    >
  • > I really wonder if what I'm attempting to do is even
    > possible without subclassing

    It possible via subclassing but an easier solution is to implement the
    delegate function:

    splitView:resizeSubviewsWithOldSize:

    This gives you the chance to determine the size of the view on resize.

    You can also do it via the containing window delegate, but the former is
    clearer when it comes to maintaining the code.

    - (void)windowDidResize:(NSNotification *)aNotification

    Main window's delegate and check the splitView.  If it's 1 or 2 pixels big
    then it's been creeping out, just set it back to 0 as the window resizes.

    Here is the answer to your question in the documentation:

    file:///Developer/ADC%20Reference%20Library/documentation/Cocoa/Conceptual/D
    rawViews/Concepts/AboutSplitViews.html

    " When the NSSplitView is displayed‹whether it¹s being displayed for the
    first time or redisplayed because the user resized the NSSplitView¹s
    window‹it checks to see if its subviews are properly tiled. If not, it
    invokes the delegate method splitView:resizeSubviewsWithOldSize:, allowing
    the delegate to specify the heights (or widths) of specific subviews. If the
    delegate doesn¹t implement this method, the NSSplitView sends adjustSubviews
    to itself to resize the subviews proportionately. Note that the NSSplitView
    doesn¹t call the delegate methods
    splitView:constrainMaxCoordinate:ofSubviewAt:,
    splitView:constrainMinCoordinate:ofSubviewAt:, or
    splitView:constrainSplitPosition:ofSubviewAt: and may resize its subviews in
    a way that isn¹t allowed by these delegate methods."

    Regards,

    Conor Dearden
    www.bruji.com
  • Well, I was able to do it by setting a "manual resize" flag in
    splitViewWillResizeSubviews, which allows me to distinguish between
    resizing by dragging a divider, or if the panes are shaped by
    resizing the superview (the parent window). In
    resizeSubviewsWithOldSize, I can then preserve the state of my
    collapsed panes before invoking adjustSubviews, and restoring their
    state afterwards.

    This is somewhat annoying to have to do, but it works great. Thanks
    for your help!

    - .Dustin

    On Jan 31, 2006, at 4:59 AM, Conor Dearden wrote:

    >> I really wonder if what I'm attempting to do is even
    >> possible without subclassing
    >
    > It possible via subclassing but an easier solution is to implement the
    > delegate function:
    >
    > splitView:resizeSubviewsWithOldSize:
    >
    > This gives you the chance to determine the size of the view on resize.
    >
    >
    > You can also do it via the containing window delegate, but the
    > former is
    > clearer when it comes to maintaining the code.
    >
    > - (void)windowDidResize:(NSNotification *)aNotification
    >
    > Main window's delegate and check the splitView.  If it's 1 or 2
    > pixels big
    > then it's been creeping out, just set it back to 0 as the window
    > resizes.
    >
    >
    > Here is the answer to your question in the documentation:
    >
    > file:///Developer/ADC%20Reference%20Library/documentation/Cocoa/
    > Conceptual/D
    > rawViews/Concepts/AboutSplitViews.html
    >
    > " When the NSSplitView is displayed—whether it’s being displayed
    > for the
    > first time or redisplayed because the user resized the NSSplitView’s
    > window—it checks to see if its subviews are properly tiled. If not, it
    > invokes the delegate method splitView:resizeSubviewsWithOldSize:,
    > allowing
    > the delegate to specify the heights (or widths) of specific
    > subviews. If the
    > delegate doesn’t implement this method, the NSSplitView sends
    > adjustSubviews
    > to itself to resize the subviews proportionately. Note that the
    > NSSplitView
    > doesn’t call the delegate methods
    > splitView:constrainMaxCoordinate:ofSubviewAt:,
    > splitView:constrainMinCoordinate:ofSubviewAt:, or
    > splitView:constrainSplitPosition:ofSubviewAt: and may resize its
    > subviews in
    > a way that isn’t allowed by these delegate methods."
    >
    > Regards,
    >
    > Conor Dearden
    > www.bruji.com
    >
    >
    > _______________________________________________
    > Do not post admin requests to the list. They will be ignored.
    > Cocoa-dev mailing list      (<Cocoa-dev...>)
    > Help/Unsubscribe/Update your Subscription:
    > http://lists.apple.com/mailman/options/cocoa-dev/dwenz%
    > 40iscompanies.com
    >
    > This email sent to <dwenz...>
    >
  • On Jan 31, 2006, at 11:46 AM, Philip Dow wrote:

    > Try RBSplitView instead: http://www.brockerhoff.net/src/rbs.html

    Did anyone managed to compile it with Xcode 2.2?

    TIA

    gt
previous month january 2006 next month
MTWTFSS
            1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31          
Go to today