简体   繁体   English

如何知道NSWindow在Mac OS X Lion中是否全屏?

[英]How to know if a NSWindow is fullscreen in Mac OS X Lion?

I guess I should check if [NSApplication presentationOptions] contains NSFullScreenModeApplicationPresentationOptions , but how do I achieve that? 我想我应该检查[NSApplication presentationOptions]包含NSFullScreenModeApplicationPresentationOptions ,但我该如何实现呢?

EDIT: using [NSApplication presentationOptions] doesn't work as in my document-based app there might be some documents in fullscreen and others not. 编辑:使用[NSApplication presentationOptions]不能像在我的基于文档的应用程序中那样,全屏可能有一些文档而其他文档没有。 I'm now looking for another solution. 我现在正在寻找另一种解决方案。 I'm wondering why there isn't a property called [NSWindow isFullscreen] or something like that. 我想知道为什么没有一个名为[NSWindow isFullscreen]的属性或类似的东西。

I was just looking for a solution myself and based on Matthieu's answer I created a category on NSWindow that works fine for me. 我本人只是在寻找解决方案,根据Matthieu的回答,我在NSWindow上创建了一个对我来说很好的类别。

@interface NSWindow (FullScreen)

- (BOOL)mn_isFullScreen;

@end

@implementation NSWindow (FullScreen)

- (BOOL)mn_isFullScreen
{
    return (([self styleMask] & NSFullScreenWindowMask) == NSFullScreenWindowMask);
}

@end

You need to use an & bitwise operator to test that that option is being used. 您需要使用&按位运算符来测试正在使用该选项。 Not tested but probably something like this: 没有经过测试,但可能是这样的:

- (BOOL) inFullScreenMode {
    NSApplicationPresentationOptions opts = [[NSApplication sharedApplication ] presentationOptions];
    if ( opts & NSApplicationPresentationFullScreen) {
       return YES;
    }
    return NO;
}

To see if any of your windows are in full screen mode simply check the style mask of the window. 要查看是否有任何窗口处于全屏模式,只需检查窗口的样式掩码。

NSUInteger masks = [someNSWindow styleMask]
if ( masks & NSFullScreenWindowMask) {
 // Do something
}

For Swift 3.0 对于Swift 3.0

if let window = NSApp.mainWindow {
    let isWindowFullscreen = window.styleMask.contains(NSFullScreenWindowMask)
}

Obviously, for the original question, you'd replace NSApp.mainWindow with whichever document window you're wanting to check. 显然,对于原始问题,您需要将NSApp.mainWindow替换为您想要检查的文档窗口。

The way I handled it in pre-10.7 (where neither NSApplicationPresentationFullScreen nor NSFullScreenWindowMask was available) was to check 我在10.7之前( NSApplicationPresentationFullScreenNSFullScreenWindowMask都不可用)处理它的方式是检查

if ([mainWindow frame].size.height == [[mainWindow screen] frame].size.height)
{
    // window is fullscreen
}

and this piece of really old code seem to still work not only on "Lion" but also on today's - at the time of writing 10.14.x - OS. 这段非常古老的代码似乎仍然不仅适用于“Lion”,而且还适用于今天 - 在编写10.14.x时 - OS。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM