问题描述
我有一个Swift应用程序,它正在启动一个简单的NSWindow
,如下所示:
I have a Swift application that is launching a simple NSWindow
, like so:
func applicationDidFinishLaunching(notification: NSNotification!) {
let storyboard = NSStoryboard(name: "MainStoryboard", bundle: NSBundle.mainBundle())
windowController = storyboard.instantiateInitialController() as? NSWindowController
windowController?.showWindow(self)
}
这很好用,我的应用程序启动并显示窗口. 但是:大小始终相同.
This works great, my app launches and the window appears. However: The size is always the same.
在情节提要中,我指定了Autosave
名称:
In the storyboard, I have specified an Autosave
name:
请注意,还选中了Restorable
复选框.
Note also the Restorable
checkbox is checked.
但是无论如何,窗口每次都会显示相同的大小.在过去,这始终是有效的",因此我无法确定这是错误还是缺失的部分.手动实例化和显示窗口时,自动保存会自动与情节提要一起使用吗?
But regardless, the window appears the same size, every time. This has always "just worked" in the past, so I can't tell if this is a bug, or a piece I'm missing. Does autosaving automatically work with storyboards when instantiating and showing windows manually?
推荐答案
这似乎是Xcode错误.我可以通过手动设置NSWindowController
windowFrameAutosaveName
属性来解决该问题:
This seems to be an Xcode bug. I was able to workaround it by manually setting the NSWindowController
windowFrameAutosaveName
property:
windowController?.windowFrameAutosaveName = "Main App Window"
但是...仅当属性设置为与Interface Builder中显示的值不同的 值时,这才对我有用.如果以编程方式将其设置为与IB中使用的值相同,那么它将不起作用.
However... This only worked for me if the property was set to a different value than what is displayed in Interface Builder. If it's programmatically set to the same value that's being used in IB, it doesn't work.
因此在IB中,自动保存名称保留为MainAppWindow
,并以编程方式将其设置为Main App Window
.
So in IB the autosave name is left to MainAppWindow
, and programmatically it's set to Main App Window
.
这篇关于使用Storyboard的NSWindowController自动保存的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!