【发布时间】:2010-10-20 09:47:09
【问题描述】:
我有一个 Cocoa 应用程序,它使用 NSAlert 类显示应用程序模式警报。我希望警报窗口浮动在所有其他应用程序的窗口之上。这可以用NSAlert 完成,还是我需要实现自己的窗口?
我不知道这些是否重要,但该应用程序是一个代理应用程序(LSUIElement 是真的)实现为NSStatusItem。 (有关该应用程序的更多信息,包括源代码,请查看<here>。)
这是显示警报的代码:
- (void)showTimerExpiredAlert {
[NSApp activateIgnoringOtherApps:YES];
NSAlert *alert = [[NSAlert alloc] init];
[alert setAlertStyle:NSInformationalAlertStyle];
[alert setMessageText:NSLocalizedString(@"Menubar Countdown Complete", @"Expiration message")];
[alert setInformativeText:NSLocalizedString(@"The countdown timer has reached 00:00:00.",
@"Expiration information")];
[alert addButtonWithTitle:NSLocalizedString(@"OK", @"OK button title")];
[alert addButtonWithTitle:NSLocalizedString(@"Restart Countdown...", @"Restart button title")];
NSInteger clickedButton = [alert runModal];
[alert release];
if (clickedButton == NSAlertSecondButtonReturn) {
// ...
}
}
我试过把这个放在runModal 调用之前:
[[alert window] setFloatingPanel:YES];
我也试过这个:
[[alert window] setLevel:NSFloatingWindowLevel];
但是如果我单击另一个应用程序的窗口,这些都不会使窗口停留在其他窗口之上。我怀疑runModal 只是不尊重这些设置。
【问题讨论】:
-
每当调用 runModal 时,它都会重置窗口级别,不确定是否有帮助...