NSSplitView have delegate methods where we control the minimum and maximum sizes of sections and which views expand or collapse by what amount.
Constraining the coordinates in the splitView:constrainMinCoordinate:ofSubviewAt: sets the minimum size of the view. 
- (CGFloat)splitView:(NSSplitView *)sender
constrainMinCoordinate:(CGFloat)proposedMin ofSubviewAt:(NSInteger)offset
{
    NSView *subview = [[sender subviews] objectAtIndex:offset];
    NSRect subviewFrame = subview.frame;
    CGFloat frameOrigin;
    if ([sender isVertical])
    {
        frameOrigin = subviewFrame.origin.x;
    }
    else
    {
        frameOrigin = subviewFrame.origin.y;
    }
    CGFloat minimumSize =
    [[lengthsByViewIndex objectForKey:[NSNumber numberWithInteger:offset]]
     doubleValue];
    return frameOrigin + minimumSize;
}
The splitView:constrainMaxCoordinate:ofSubviewAt: delegate sets the maximum size of the views.
- (CGFloat)splitView:(NSSplitView *)sender
constrainMaxCoordinate:(CGFloat)proposedMax ofSubviewAt:(NSInteger)offset
{
    NSView *growingSubview = [[sender subviews] objectAtIndex:offset];
    NSView *shrinkingSubview = [[sender subviews] objectAtIndex:offset + 1];
    NSRect growingSubviewFrame = growingSubview.frame;
    NSRect shrinkingSubviewFrame = shrinkingSubview.frame;
    CGFloat shrinkingSize;
    CGFloat currentCoordinate;
    if ([sender isVertical])
    {
        currentCoordinate=growingSubviewFrame.origin.x + growingSubviewFrame.size.width;
        shrinkingSize = shrinkingSubviewFrame.size.width;
    }
    else
    {
        currentCoordinate = growingSubviewFrame.origin.y + growingSubviewFrame.size.height;
        shrinkingSize = shrinkingSubviewFrame.size.height;
    }
    CGFloat minimumSize =
    [[lengthsByViewIndex objectForKey:[NSNumber numberWithInteger:offset + 1]]
     doubleValue];
    return currentCoordinate + (shrinkingSize - minimumSize);
}
                       
                    
0 Comment(s)