我正在使用MAAttachedWindow在菜单栏中的NSStatusItem下显示自定义窗口。
一切正常,但是当用户在窗口外部单击时,我找不到隐藏它的简便方法。我要实现此行为,因为这是用户期望的。
这是用于显示MAAttachedWindow
的代码:
- (void)toggleAttachedWindowAtPoint:(NSPoint)pt {
if (!self.attachedWindow) {
self.attachedWindow = [[MAAttachedWindow alloc] initWithView:logView
attachedToPoint:pt
inWindow:nil
onSide:MAPositionBottom
atDistance:5.0];
[self.attachedWindow setLevel:kCGMaximumWindowLevel];
}
if(isVisible)
[self.attachedWindow makeKeyAndOrderFront:self];
else
[self.attachedWindow orderOut];
}
该代码由具有自定义视图的
NSStatusItem
触发,该视图拦截了对其的单击。 最佳答案
您应该可以通过窗口的委托方法执行此操作:- (void)windowDidResignKey:(NSNotification *)notification
将您自己设置为窗口的委托,并实现该委托以调用您的toggle方法。