1
votes

I've made an NSWindow in Interface Builder. Inside this window is an NSScrollView and inside that is a custom NSView.

The NSScrollview fills the NSWindow and the custom NSView fills the NSScrollview.

When the custom NSView is sent the awakeFromNib method its bounds are 0,0 and 256x373 as I'd expect, filling the scrollview.

However later I change the size of the NSView to be larger than 373high but it never changes size in the scrollview. I've tried setting the frame, I've tried setting the bounds, but nothing makes it change.

Except, when I tried changing the intrinsicSize of the custom NSView it did change, but it made the NSWindow and NSScrollview change sizes as well to fit the new size of 256x1452

Can anyone tell me where I might be going wrong? Is it something to do with the constraints set on the Scrollview or the NSView? I haven't set any but when I added the items in Interface Builder they were automatically added for me

[EDIT]

I've changed it so that the custom NSView is created programmatically and added to the NSScrollView with setDocumentView: and everything works as I expect. So I guess technically I've solved the problem, but I'd still like an explanation on why it's not working via Interface Builder if anyone knows.

1

1 Answers

1
votes

I have a partial solution, which also causes me to pose an additional question. I had a similar issue, I needed to programatically change the size of a view embedded in a NSScrolView.

This code works, need both methods

-(void)markViewSizeChanged /* Works correctly */
{
    [self setFrameSize:currentViewSize];
    [self setBoundsSize:currentViewSize];
    [self setNeedsDisplay:YES];
}


-(NSSize)intrinsicContentSize // Override of class method
{
    return currentViewSize;
}

Note: MUST set currentViewSize in awakeFromNib

Now for the curious part. If I reverse the order of the two calls setting the frame and bounds, the size of the embedded view is correct, but the scaling factor of objects drawn is off.

-(void)markViewSizeChanged /* DOES NOT work correctly, scaling in drawing off */
{
    [self setBoundsSize:currentViewSize];
    [self setFrameSize:currentViewSize];
    [self setNeedsDisplay:YES];
}