問題描述
我正在使用 MAAttachedWindow 在下顯示自定義窗口菜單欄中的 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
的代碼:
- (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 *)notification
將自己設置為窗口的委托,并實現它以調用您的切換方法.
Set yourself as the window's delegate, and implement that to call through to your toggle method.
這篇關于單擊外部時隱藏 MAAttachedWindow的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!