Showing a modal NSWindow, without activating the other application windows

人走茶凉 提交于 2019-11-29 00:08:27

Instead of creating an NSWindow, create an NSPanel with the style NSNonactivatingPanelMask. You can then do the usual makeKeyAndOrderFront: and orderOut: to show/hide panel as needed.

cSquirrel

NSApp's beginModalSessionForWindow, runModalSession, endModalSession are methods you need.

Have a look here for example how to use it: Creating a fully customized NSAlert

mralex

A solution by Ken Thomases on the cocoa-dev list a couple years ago looks applicable here too:

[[NSApplication sharedApplication] hide:self];
[[NSApplication sharedApplication] performSelector:@selector(unhideWithoutActivation) 
                                        withObject:nil 
                                        afterDelay:0.05];

Which in theory tells the application to hide itself and unhide at the bottom of the window stack.

You could also intercept the mouse click event and use [NSApp preventWindowOrdering]

You can try something like:

...
if ([NSApp isHidden])
    [myWindow makeKeyAndOrderFront:self];
else
    [NSApp runModalForWindow:myWindow];
... 

and when finish:

...
if ([NSApp isHidden])
    [myWindow orderOut:self];
else
    [NSApp stopModal];
... 
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!