Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • NSSplitView delegate for controlling minimum and maximum sizes of views

    • 0
    • 1
    • 1
    • 1
    • 0
    • 0
    • 0
    • 0
    • 1.59k
    Comment on it

    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)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: