调整大小NSWindow以适应子NSView [英] Resizing NSWindow to fit child NSView

查看:2567
本文介绍了调整大小NSWindow以适应子NSView的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个主要的NSWindow是空的,和5 NSViews。 NSView有不同的按钮和标签等,窗口是空的。显示的第一个视图是一个菜单,链接到其他视图和返回。

I have one main NSWindow which is empty, and 5 NSViews. The NSViews have different buttons and labels etc, and the window is empty. The first view displayed is a menu, linking to the other views and back. This works fine and the views switch well.

然而,如果NSWindow是一个特定的大小,NSView是更大的,那么它会溢出NSWindow,并被截断。

However if the NSWindow is a certain size, and the NSView is bigger, then it spills out of the NSWindow and gets cut off.

有什么办法让我这样做:

Is there any way such that when I do:

[_window setContentView: theNewView];

还具有 _window 新视图?如果这是可能的,可以使用动画吗?

to also have _window resize to fit the new view? If this is possible, can this be done with an animation?

推荐答案

- [NSWindow setContentSize:] 执行此操作(无动画)。给它所需的内容视图大小,它将适当调整内容视图和窗口的大小,例如

-[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];



,然后用 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];

这篇关于调整大小NSWindow以适应子NSView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆