NSAlert
クラスを使用してアプリケーションモーダルアラートを表示するCocoaアプリケーションがあります。アラートウィンドウを他のすべてのアプリケーションのウィンドウの上に表示したいのですが。これはで実行できますNSAlert
か、それとも独自のウィンドウを実装する必要がありますか?
これが重要かどうかはわかりませんが、アプリケーションはLSUIElement
として実装されたエージェントアプリケーション(true)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
はこれらの設定のどちらも尊重していないのではないかと思います。