Resize NSWindow to Install a Child NSView

I have one main NSWindow that is empty, and 5 NSViews. NSViews have different buttons and tags, etc., and the window is empty. The first displayed view is a menu linked to other views and back. This works great and the views switch well.

However, if the NSWindow is of a certain size, and the NSView is larger, then it spills out of the NSWindow and is trimmed.

Is there a way that when I do this:

[_window setContentView: theNewView];

also be sized _windowto fit the new view? If possible, can this be done with animation?

+3
source share
1 answer

-[NSWindow setContentSize:] ( ). , , , .

[_window setContentSize:theNewView.frame.size];
[_window setContentView:theNewView];

frameRectForContentRect:, animate:YES:

[_window setContentView:theNewView];
NSRect viewScreenFrame = /*translate theNewView.frame to screen coordinates*/;
NSRect wndFrame = [_window frameRectForContentRect:viewScreenFrame];
[_window setFrame:wndFrame display:YES animate:YES];
+14

All Articles