Search code examples
notificationssplitternssplitview

NSSplitView splitter pane change notification


Hello I need to implement four views splitters like in Maya, 3ds max, Blender or other similar modeling tools. I use NSSplitView on Mac side of my editor and I need to know when user drags one pane to sync another pane.
Is there any way to get new size from one NSSplitView and sync another view to it? I have working code for Windows Forms in C# version of this editor, but I can't figure out how to do it on a Mac. Full source code is at http://github.com/filipkunc/opengl-editor-cocoa.

Thanks a lot.


Solution

  • I fixed it with this code:

    - (void)splitViewDidResizeSubviews:(NSNotification *)notification
    {
        NSSplitView *splitView = (NSSplitView *)[notification object];
        NSView *topSubview0 = (NSView *)[[topSplit subviews] objectAtIndex:0];
        NSView *topSubview1 = (NSView *)[[topSplit subviews] objectAtIndex:1];
    
        NSView *bottomSubview0 = (NSView *)[[bottomSplit subviews] objectAtIndex:0];
        NSView *bottomSubview1 = (NSView *)[[bottomSplit subviews] objectAtIndex:1];
    
        if (fabsf([bottomSubview0 frame].size.width - [topSubview0 frame].size.width) >= 1.0f)
        {
            if (splitView == topSplit)
            {
                NSLog(@"topSplit");
                [bottomSubview0 setFrame:[topSubview0 frame]];
                [bottomSubview1 setFrame:[topSubview1 frame]];
            }
            else
            {
                NSLog(@"bottomSplit");
                [topSubview0 setFrame:[bottomSubview0 frame]];
                [topSubview1 setFrame:[bottomSubview1 frame]];
            }
        }
    }