How to check if an NSWindow is open

穿精又带淫゛_ 提交于 2019-12-11 01:58:36

问题


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?

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


回答1:


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




回答2:


-[NSWindow isVisible] is not really deprecated.

For the 10.10 SDK, Apple went through and converted a bunch of informal properties to declared properties. An informal property is one for which there are just accessors declared, possibly just a getter method. A declared property uses @property.

As a consequence, they removed something like:

- (BOOL) isVisible;

and added:

@property (getter=isVisible, readonly) BOOL visible;

Note that both still imply the existence of an -isVisible getter with BOOL return type.

The tools they use to generate the documentation from the changes to their headers caused the documentation to claim that -isVisible is deprecated, but that's just wrong.

Note, though, that -isVisible reports false for a window which is minimized or which is "open" but in a hidden app.



来源:https://stackoverflow.com/questions/29253375/how-to-check-if-an-nswindow-is-open

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!