Hiding Dividers in Nssplitview

How to hide a divider of nssplitview?

The split view sends that message to its delegate, to ask the delegate whether it should hide that divider. So, be the delegate, and answer the split view's question.

Be sure to check out the documentation. It's possible that that message won't accomplish what you want it to. The documentation lists everything you can do by responding to that message.

Hiding Dividers in NSSplitView

Ok, I went a whole different way and found a way to make it work. So if you are trying to completely customize dividers this is how you do it.

  1. Subclass NSSplitView and return 0 from dividerThickness

So your new split view won't display dividers at all now, but you can add them manually where you want them


  1. Add NSBox or your custom divider views where you want your dividers to show up in your split view subviews, preferrably at the top of the subview.

  2. Override the split view delegate method splitView(:additionalEffectiveRectOfDividerAt:) and manually return rects that match your custom NSBox dividers

You might need to convert(:from:) between NSView coordinates to get your effective rects, but it works! The delegate might look something like this

override func splitView(_ splitView: NSSplitView, additionalEffectiveRectOfDividerAt dividerIndex: Int) -> NSRect {
let item = splitViewItems[dividerIndex]
let itemView = item.viewController.view
let frame = view.convert(itemView.bounds, from: itemView)

let dividerFrame = CGRect(x: 0,
y: view.bounds.height - frame.minY,
width: frame.width,
height: 1)

return dividerFrame
}

There you have it. Custom dividers that also work with animations!

How to Hide Divider when NSSplitView subview is Collapsed?

The solution was rather simple.

Just implement - (BOOL)splitView:(NSSplitView *)splitView shouldHideDividerAtIndex:(NSInteger)dividerIndex somewhere inside DMSplitView.m and makes sure it behaves as you wish.

How to toggle visibility of NSSplitView subView + hide Pane Splitter divider?

Here's a pretty decent tutorial that shows how to do this: Unraveling the Mysteries of NSSplitView.

Hiding the divider is done in NSSplitView's delegate method splitView:shouldHideDividerAtIndex:.

You will have to animate the frame size change yourself if you don't like the way NSSplitView does it.

Make the divider of an NSSplitView undraggable and don't show the dragging cursor

Try using splitView:constrainMaxCoordinate:ofSubviewAt: and splitView:constrainMinCoordinate:ofSubviewAt: instead of splitView:constrainSplitPosition:ofSubviewAt:.

The former two methods are called once as the user drags the mouse and they give enough information for NSSplitView to know how to change the cursor during the drag.

The latter is called repeatedly as the user drags the splitter, so NSSplitView doesn't have enough information to know that you're returning a constant value each time and therefore can't change the cursor.

Change divider positions in NSSplitView when subviews change

To programmatically set the position of a divider, invoke -setPosition:ofDividerAtIndex: on your NSSplitView.

How to get NSSplitView splitView:shouldHideDividerAtIndex:to be called at startup?

The solution is to use the same fix for a window growing in size at each launch when the title is hidden: https://openradar.appspot.com/18510665

You have to remove the autosave name from Interface Builder (IB) and do it programatically after the window has loaded and the frames have been set:

override func windowDidLoad() {
super.windowDidLoad()
//...
splitView.autosaveName = "YourAutosaveName"
//...
}

How to disable accessibility support for the divider of a NSSplitView?

Ok, I asked a nice guy from the AppKit team at WWDC.
He told me that this is not possible at the moment - because I can not acces the divider within the splitView.

Explanation:
Disabling the accessibility support on a NSView, makes the particular view inaccessible, but not its sub view - which is the desired behavior normally

Since the divider is a subview of NSSplitView, this does not work.

Solution:
I ended up not using NSSplitView anymore because I don't need any of the class specific features. The dividers are fixed in my application.

Instead I used NSStackView to encapsulate my subviews - and it works perfectly. (Hide and show subviews)

How to change color of divider in NSSplitView?

I've tried subclassing - (void)dividerColor too and I'm not sure why it doesn't work even though I know it's being called (and it's in the documentation).

One way to change the color of the divider is to subclass - (void)drawDividerInRect:(NSRect)aRect. However, for some reason, this method isn't called and I've checked all over the web for answers, but couldn't find anything, so I ended up calling it from drawRect. Here is the code for the subclassed NSSplitView:

-(void) drawRect {
id topView = [[self subviews] objectAtIndex:0];
NSRect topViewFrameRect = [topView frame];
[self drawDividerInRect:NSMakeRect(topViewFrameRect.origin.x, topViewFrameRect.size.height, topViewFrameRect.size.width, [self dividerThickness] )];
}

-(void) drawDividerInRect:(NSRect)aRect {
[[NSColor redColor] set];
NSRectFill(aRect);
}


Related Topics



Leave a reply



Submit