ฉันมีแอปพลิเคชัน 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
ไม่ให้เกียรติการตั้งค่าอย่างใดอย่างหนึ่งเหล่านั้น