单击外部时隐藏 MAAttachedWindow

Hide MAAttachedWindow when clicking outside(单击外部时隐藏 MAAttachedWindow)
本文介绍了单击外部时隐藏 MAAttachedWindow的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

问题描述

我正在使用 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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

相关文档推荐

AWS DynamoDB Batch Get Request - iOS(AWS DynamoDB 批量获取请求 - iOS)
DynamoDB auto incremented ID amp; server time (iOS SDK)(DynamoDB 自动递增 ID amp;服务器时间(iOS SDK))
dynamodb scanexpression with scan filter in objective-c(在objective-c中带有扫描过滤器的dynamodb scanexpression)
Getting full access to DynamoDB from my ios app using AWS Cognito Developer Identities(使用 AWS Cognito 开发人员身份从我的 ios 应用程序获得对 DynamoDB 的完全访问权限)
iOS framework with dependencies(具有依赖项的 iOS 框架)
Editing locked files from a CocoaPods framework(从 CocoaPods 框架编辑锁定的文件)