[英]Get Notification of NSStatusItem frame change?
在使用帶有自定義視圖的NSStatusItem
的應用程序中,如下所示:
...如何在以下情況下收到通知:
當項目更改位置時,兩者都是將自定義視圖移動到正確位置所必需的。
有一個方法-[NSStatusItem setView:]
。 為狀態項設置自定義視圖時,此視圖將自動插入特殊狀態欄窗口。 您可以使用方法-[NSView window]
訪問該窗口以觀察其NSWindowDidMoveNotification
:
- (void)applicationDidFinishLaunching:(NSNotification *)notification
{
NSStatusItem *statusItem = [self newStatusItem];
NSView *statusItemView = [self newStatusItemView];
statusItem.view = statusItemView;
NSNotificationCenter *dnc = [NSNotificationCenter defaultCenter];
[dnc addObserver:self selector:@selector(statusBarDidMove:)
name:NSWindowDidMoveNotification object:statusItemView.window];
}
- (void)statusBarDidMove:(NSNotification *)note
{
NSWindow *window = note.object;
NSLog(@"%@", NSStringFromRect(window.frame)); // i.e. {{1159, 900}, {24, 22}}
}
每次狀態欄變為可見或隱藏以及移動圖標時,您都會收到通知。 這是您更新彈出式面板位置的機會。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.