jsa*_*eew 2 cocoa objective-c event-handling show-hide nswindow
我正在使用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];
}
Run Code Online (Sandbox Code Playgroud)
此代码由NSStatusItem自定义视图触发,该视图拦截对其的单击.
您应该可以通过窗口的委托方法执行此操作:
- (void)windowDidResignKey:(NSNotification *)notification
将自己设置为窗口的委托,并实现它以调用切换方法.
| 归档时间: |
|
| 查看次数: |
1863 次 |
| 最近记录: |