gpt4 book ai didi

swift - 以编程方式隐藏和关闭当前 NSViewController 的窗口

转载 作者:行者123 更新时间:2023-11-28 15:06:39 27 4
gpt4 key购买 nike

我想在 func viewDidLoad() 中隐藏/关闭我的主应用程序窗口,并且仅在某些事件需要时才显示/取消隐藏主窗口。

我试过 self.view.window?.close() 但这会留下一个白色窗口。我还尝试了 NSApp.hide(nil) 但后来我无法使用 NSApp.unhide(nil) 取消隐藏。这是一些示例代码:

override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
NSApp.hide(nil)
runTest()
}

func runTest () {
let check = false

if check == false {
NSApp.unhide(nil)
}
}

最佳答案

来自NSWindow documentation

func orderOut(_ sender: Any?)

Removes the window from the screen list, which hides the window.

func makeKeyAndOrderFront(_ sender: Any?)

Moves the window to the front of the screen list, within its level, and makes it the key window; that is, it shows the window.

HideClose 是两个不同的东西:

If the window is the key or main window, the window object immediately behind it is made key or main in its place. Calling orderOut(_:) causes the window to be removed from the screen, but does not cause it to be released. See the close() method for information on when a window is released. Calling orderOut(_:) on a child window causes the window to be removed from its parent window before being removed.

隐藏应用程序 (NSApp.hide(nil) 是另一回事:它

Hides all the receiver’s windows, and the next app in line is activated.

关于swift - 以编程方式隐藏和关闭当前 NSViewController 的窗口,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48353000/

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