如何检查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?
我已经阅读了文档和Googled,但是看不到执行此操作的理智方法. [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屋!