单击外部时隐藏MAAttachedWindow [英] Hide MAAttachedWindow when clicking outside
问题描述
我正在使用 MAAttachedWindow 显示一个自定义窗口在Menubar中的NSStatusItem。
一切正常,但是当用户在窗口外点击时,我找不到一种简单的方式来隐藏它。我想实现这个行为,因为它是用户期望的。
I'm using an MAAttachedWindow to display a custom window under a NSStatusItem in the Menubar. Everything works fine, but I can't find an easy way to hide it when the user clicks outside of the window. I want to implement this behavior because it's what the user expects.
这是用于显示 MAAttachedWindow
:$ {
This is the code used to display the 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
具有拦截点击的自定义视图。
This code gets triggered by an NSStatusItem
with a custom view which intercepts a click on it.
推荐答案
您应该可以通过窗口委托方法:
You should be able to do this via the window's delegate method:
- (void)windowDidResignKey:(NSNotification *)通知
将自己设置为窗口的代理,并实现该功能来调用切换方法。
Set yourself as the window's delegate, and implement that to call through to your toggle method.
这篇关于单击外部时隐藏MAAttachedWindow的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!