如何检查 NSWindow 是否打开 [英] How to check if an NSWindow is open
问题描述
我有一个 NSWindow
可以关闭和重新打开(我调用了 [setReleasedWhenClosed: NO]
).如何以编程方式检查它是打开还是关闭?
I have an NSWindow
which can be closed and reopened (I've called [setReleasedWhenClosed: NO]
). How do I check if it is open or closed programmatically?
我已经阅读了文档并在谷歌上搜索过,但看不到一种明智的方法来做到这一点.[isVisible]
已弃用.[occlusionState]
不是我想要的.我已经使用通知解决了这个问题,但我不敢相信 NSWindow
上没有任何属性或方法来执行此操作
I've read the doc and Googled but can't see a sane way to do this. [isVisible]
is deprecated. [occlusionState]
isn't what I'm after. I've worked around it using notifications, but I can't believe there isn't some property or method on NSWindow
to do this
推荐答案
你利用了 NSWindow 的 screen 属性.如果窗口在屏幕外,它将返回 nil.请检查 https://developer.apple.com/library/mac/documentation/Cocoa/Reference/ApplicationKit/Classes/NSWindow_Class/index.html#//apple_ref/occ/instm/NSWindow/screen
You make make of use of screen property of NSWindow. If the window in offscreen it will return nil. Please check https://developer.apple.com/library/mac/documentation/Cocoa/Reference/ApplicationKit/Classes/NSWindow_Class/index.html#//apple_ref/occ/instm/NSWindow/screen
这篇关于如何检查 NSWindow 是否打开的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!