macos – 获取NSStatusItem框架更改的通知?

在使用带有自定义视图的NsstatusItem的应用程序中,如下所示:

…如何在以下情况下收到通知

>状态栏因全屏应用而被隐藏
>状态项移动位置,因为添加/删除/调整了其他项目的大小?

当项目更改位置时,两者都是将自定义视图移动到正确位置所必需的.

解决方法

一个方法 – [NsstatusItem setView:].为状态项设置自定义视图时,此视图将自动插入特殊状态栏窗口.您可以使用方法 – [NSView窗口]访问该窗口以观察其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}}
}

每次状态栏变为可见或隐藏以及移动图标时,您都会收到通知.这是您更新弹出式面板位置的机会.

相关文章

我正在用TitaniumDeveloper编写一个应用程序,它允许我使用Ja...
我的问题是当我尝试从UIWebView中调用我的AngularJS应用程序...
我想获取在我的Mac上运行的所有前台应用程序的应用程序图标....
我是一名PHP开发人员,我使用MVC模式和面向对象的代码.我真的...
OSX中的SetTimer在Windows中是否有任何等效功能?我正在使用...
我不确定引擎盖下到底发生了什么,但这是我的设置,示例代码和...