调整NSWindow的大小以匹配情节提要中的视图控制器大小 [英] Resizing NSWindow to match view controller size in storyboard

查看:112
本文介绍了调整NSWindow的大小以匹配情节提要中的视图控制器大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在OSX 10.10上使用Xcode 6.1.1.我正在尝试Mac应用程序的情节提要.我有一个使用新的NSTabViewControllerTabStyleToolbar tabStyle的NSTabViewController,它被设置为窗口控制器的默认视图控制器. 如何根据当前选定的视图控制器调整窗口大小?

I am working on Xcode 6.1.1 on OSX 10.10. I am trying out storyboards for Mac apps. I have a NSTabViewController using the new NSTabViewControllerTabStyleToolbar tabStyle and it is set as the default view controller for the window controller. How do I make my window resize according to the current selected view controller?

是否可以完全在Interface Builder中完成? 这是我的情节提要的样子:

Is it possible to do entirely in Interface Builder? Here is what my storyboard looks like:

推荐答案

自动布局的答案是其中的一半.您需要在ViewController中将每个选项卡的preferredContentSize设置为合适的大小(如果您希望将选项卡的大小设置为满足所有约束的最小大小).

The auto layout answer is half of it. You need to set the preferredContentSize in your ViewController for each tab to the fitting size (if you wanted the tab to size to the smallest size satisfying all constraints).

override func viewWillAppear() {
        super.viewWillAppear()
        preferredContentSize = view.fittingSize
}

如果您的约束导致以下问题,请首先尝试使用固定大小,以下示例在选项卡项目的视图控制器的viewWillAppear函数中设置了此值(此处使用了Swift,但是Objective-C版本也可以使用).

If your constraints are causing an issue below try first with a fixed size, the example below sets this in the tab item's view controller's viewWillAppear function (Swift used here, but the Objective-C version works just as well).

override func viewWillAppear() {
        super.viewWillAppear()
        preferredContentSize = NSSize(width: 400, height: 280)
}

如果这行得通,请摆弄您的约束以弄清楚发生了什么

If that works, fiddle with your constraints to figure out what's going on

这篇关于调整NSWindow的大小以匹配情节提要中的视图控制器大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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