I've got a background process that makes a transparent window appear when a hotkey is pressed:
我有一个背景流程,当按下热键时,会出现一个透明的窗口:
[window makeKeyAndOrderFront:nil];
[[content animator] setAlphaValue:1.0]; // alpha was 0.0
... the window shows up fine & in front of the other windows (as I want it to), however until I manually click the window whatever application was active when the window appears remains active. I was expecting the 'makeKeyAndOrderFront' to make the application active as well, however adding a NSLog line to my -applicationWillBecomeActive shows it's not getting any active notification until the mouse click is performed.
…窗口显示得很好,并且在其他窗口前(我希望如此),但是,直到我手动单击窗口时,窗口出现时任何应用程序都是活动的。我希望“makeKeyAndOrderFront”也能使应用程序处于活动状态,但是在我的- applicationwilleactive行中添加一个NSLog行,表明它在执行鼠标单击之前没有收到任何活动通知。
Does anyone know how I can set my application active @ the same time I issue the -makeKeyAndOrderFront ? I need it active so that it can begin accepting keyboard input - any assistance needed :-)
有谁知道我如何在我发布-makeKeyAndOrderFront的同时激活我的应用程序吗?我需要它活跃,以便它可以开始接受键盘输入-任何需要的协助:
2 个解决方案
#1
48
Look at [[NSApplication sharedApplication] activateIgnoringOtherApps : YES];
.
看看[[NSApplication sharedApplication] activateIgnoringOtherApps:是的];
#2
9
For 10.6 or greater
为10.6或更高版本
[[NSRunningApplication currentApplication] activateWithOptions:(NSApplicationActivateAllWindows | NSApplicationActivateIgnoringOtherApps)];
#1
48
Look at [[NSApplication sharedApplication] activateIgnoringOtherApps : YES];
.
看看[[NSApplication sharedApplication] activateIgnoringOtherApps:是的];
#2
9
For 10.6 or greater
为10.6或更高版本
[[NSRunningApplication currentApplication] activateWithOptions:(NSApplicationActivateAllWindows | NSApplicationActivateIgnoringOtherApps)];