NSAlert
我有一个 Cocoa 应用程序,它使用该类显示应用程序模式警报。我希望警报窗口浮动在所有其他应用程序的窗口之上。这可以用 来完成NSAlert
,还是我需要实现自己的窗口?
我不知道这些是否重要,但该应用程序是一个代理应用程序(LSUIElement
是真的),实现为NSStatusItem
. (有关该应用程序的更多信息,包括源代码,请查看<此处>。)
这是显示警报的代码:
- (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
只是不尊重这些设置中的任何一个。