我有这段代码隐藏了所有正在运行的应用程序窗口,但Finder除外。
NSArray *apps = [[NSWorkspace sharedWorkspace] runningApplications];
for (NSRunningApplication *app in apps) {
if([app.bundleIdentifier.lowercaseString isEqualToString:@"com.apple.finder"]) {
[app activateWithOptions:NSApplicationActivateAllWindows|NSApplicationActivateIgnoringOtherApps];
} else {
[app hide];
}
}
但是对于非全屏窗口,它可以正常工作。
如何隐藏所有全屏窗口?
这不起作用
[NSWorkspace.sharedWorkspace hideOtherApplications];
答案 0 :(得分:1)
这就是我的做法:
// Create a tiny window on each screen to force all the full screen windows to get out of the way
for (NSScreen *screen in [NSScreen screens]) {
NSRect dummyFrame = {0,0,1,1};
NSWindow *dummyWindow = [[NSWindow alloc] initWithContentRect:dummyFrame
styleMask:NSBorderlessWindowMask
backing:NSBackingStoreBuffered
defer:NO
screen:screen];
NSView *dummyView = [[NSView alloc] initWithFrame:dummyFrame];
[dummyWindow setContentView: dummyView];
[dummyWindow makeKeyAndOrderFront:self];
}
// Now hide all the windows except for Finder's
NSArray *apps = [[NSWorkspace sharedWorkspace] runningApplications];
for (NSRunningApplication *app in apps) {
if([app.bundleIdentifier.lowercaseString isEqualToString:@"com.apple.finder"]) {
[app activateWithOptions:NSApplicationActivateAllWindows|NSApplicationActivateIgnoringOtherApps];
} else {
[app hide];
}
}