1

我创建了一个像这样的 NSStatusBar NSMenu:

- (NSMenu *)startUpViewBarMenu {
    NSMenu *menu = [[NSMenu alloc] init];

    NSMenuItem* info = [[NSMenuItem alloc] initWithTitle:@"" action:nil keyEquivalent:@""];
    //[info setTarget:self];
    [info setView:[self startUpView]];
    [menu addItem:info];

    // Disable auto enable
    [menu setAutoenablesItems:NO];
    [menu setDelegate:(id)self];
    return menu;
}

我想动态移动[self startUpView]指向图标所在位置的 NSView ()。类似于 Evernote 的做法。如您所见,它是图标的中心:在此处输入图像描述

而我的 NSStatusBar NSView 落在 NSStatusBar 图标的左侧或右侧。

所以两个问题:

如何移动下拉 NSView?

我尝试更改框架(-100),但没有区别:

NSView *view = [[NSView alloc] initWithFrame:NSMakeRect(-100, 0, 400, 471)];

如何动态移动与图标相关的下拉 NSView?

4

1 回答 1

1

Evernote 不使用菜单。这似乎是在单击您的状态项视图时触发的 NSPopover。

/* setup your status item */

self.statusItem.highlightMode = YES;
[self.statusItem setAction:@selector(showPopover:)];
[self.statusItem setTarget:put correct target here];


/* use this code to show popover */


 -(void)showPopover:(id)sender
 {
     NSWindow * aWindow = [sender window];
     NSView * aView = [aWindow contentView];
     NSPopover  * aPopover = [[NSPopover alloc] init];
     /* Setup your popover here */
     [aPopover showRelativeToRect:aView.bounds ofView:aView preferredEdge:NSMaxYEdge];
 }
于 2015-12-03T09:37:04.563 回答