我已经像这样创建了一个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;
}
我想动态移动指向图标所在位置的NSView([self startUpView]
)。与Evernote的做法类似。如您所见,它是图标的核心:
而对于我的NSStatusBar,NSView会落在NSStatusBar图标的左侧或右侧。
所以有两个问题:
我尝试过更改框架(-100),但没有区别:
NSView *view = [[NSView alloc] initWithFrame:NSMakeRect(-100, 0, 400, 471)];
答案 0 :(得分:1)
Evernote 不使用菜单。这似乎是在点击您的statusitem视图时触发的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];
}