gpt4 book ai didi

swift - 如何为多个屏幕保存 NSWindow 位置?

转载 作者:行者123 更新时间:2023-11-30 13:29:44 25 4
gpt4 key购买 nike

我正在为 IB 中的窗口设置自动保存名称。在窗口的窗口 Controller 中,我正在执行以下操作 -

  override func windowDidLoad() {
super.windowDidLoad()

// Implement this method to handle any initialization after your window controller's window has been loaded from its nib file.
self.window?.setFrameUsingName("TestWindowContollerAutoSaveName")
}

这是尽可能简单的。如果我在单屏上使用它,它会完美运行。但是如果我使用多个屏幕,那么初始窗口位置总是在主屏幕上。它不记得应用程序退出的屏幕。我也试过(没有运气)-

  override func windowDidLoad() {
super.windowDidLoad()

// Implement this method to handle any initialization after your window controller's window has been loaded from its nib file.
let frameString = self.window?.stringWithSavedFrame
if let _ = frameString{
self.window?.setFrameFromString(frameString!)
}
}

如何正确使用setFrameUsingName方法?感谢您的帮助。

最佳答案

这是因为所有 UIView 都嵌入在 UIWindow 中。每个 UIView,或者你所说的“屏幕”,都是 UIWindow 的 subview 。您可以将 UIWindow 视为 UIView 的父级。如果您只想编辑一个 UIView,请考虑只使用该 UIView。

您可以阅读更多关于 View and Window Architecture 的信息.他们在那里有一个有用的图表,也可以帮助您直观地理解我的解释。

关于swift - 如何为多个屏幕保存 NSWindow 位置?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36711047/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com