Resizing NSWindow to fit child NSView

眉间皱痕 提交于 2019-12-02 21:28:27

-[NSWindow setContentSize:] does this (without animation). Give it the desired size of the content view and it will resize both content view and the window appropriately, e.g.

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

For animation, you need to compute window size manually using frameRectForContentRect: and then change window's frame with 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];
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!