- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
当单击 NSStatusItem 时,会弹出一个自定义窗口。代码基于MAAtachedwindow 。一切都工作得很好,但当用户单击其他状态栏项目或其他应用程序等其他内容时,我无法找到关闭窗口的方法。
这是我创建窗口的代码:
statusItem = [[[NSStatusBar systemStatusBar] statusItemWithLength:width] retain];
//setup custom status menu view
CGFloat height = [[NSStatusBar systemStatusBar] thickness];
NSRect viewFrame = NSMakeRect(0.0f, 0.0f, width, height);
statusMenuView = [[[_ISStatusMenuView alloc] initWithFrame:viewFrame] retain];
statusMenuView.offset = aOffset;
statusItem.view = statusMenuView;
//setup the window to show when clicked
NSRect contentRect = NSZeroRect;
contentRect.size = aView.frame.size;
statusMenuWindow = [[[NSWindow alloc] initWithContentRect:contentRect
styleMask:NSBorderlessWindowMask
backing:NSBackingStoreBuffered
defer:NO] retain];
[statusMenuWindow setLevel:NSPopUpMenuWindowLevel];
[statusMenuWindow setBackgroundColor:[NSColor clearColor]];
[statusMenuWindow setMovableByWindowBackground:NO];
[statusMenuWindow setExcludedFromWindowsMenu:YES];
[statusMenuWindow setOpaque:NO];
[statusMenuWindow setHasShadow:NO];
[statusMenuWindow useOptimizedDrawing:YES];
[[statusMenuWindow contentView] addSubview:aView];
[statusMenuWindow setDelegate:self];
statusMenuView.statusMenuWindow = statusMenuWindow;
这是我显示窗口的方式:
- (void)centerView{
NSRect menuFrame = self.window.frame;
NSRect windowFrame = self.statusMenuWindow.frame;
NSPoint menuPoint = NSMakePoint(NSMidX(menuFrame), NSMinY(menuFrame));
menuPoint.x -= windowFrame.size.width*0.5f;
menuPoint.y -= windowFrame.size.height+self.offset;
[self.statusMenuWindow setFrameOrigin:menuPoint];
[self.statusMenuWindow makeKeyAndOrderFront:self];
}
我希望 windowDidResignKey
委托(delegate)方法能够解决问题,但此配置不会成功。委托(delegate)正在工作,因为 windowDidMove
确实运行了。
- (void)windowDidResignKey:(NSNotification *)notification{
NSLog(@"windowDidResignKey");
[statusMenuView hideView];
}
- (void)windowDidResignMain:(NSNotification *)notification{
NSLog(@"windowDidResignMain");
}
- (void)windowDidMove:(NSNotification *)notification{
NSLog(@"windowDidMove");
}
回顾一下,当用户单击其他任何内容时,如何隐藏我的自定义窗口,就像标准状态栏菜单的工作方式一样?
编辑看完Popup例如,我唯一缺少的是我必须子类化 NSPanel 并使其成为关键窗口。
@interface Panel : NSPanel
@end
@implementation Panel
- (BOOL)canBecomeKeyWindow{
return YES;
}
@end
最佳答案
您需要确保您的窗口可以成为关键窗口,并在退出关键窗口时调用您的窗口的 orderOut: 方法。如果您还没有使用自定义 NSWindowController,您应该使用自定义 NSWindowController,在这种情况下,您只需调用其“close”方法即可关闭窗口。
我建议您不要发布一堆代码,而是看一下最近发布的这个优秀的将窗口附加到状态项的示例: Shpakovski Popup Window Example
关于objective-c - 关闭 NSStatusItem 的自定义窗口,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6786453/
我是一名 .Net 开发人员,需要将一个小程序移植到 Mac OS X。我已经完成了大部分工作(部分感谢此网站上的人员,谢谢!),但有一个错误,也许我可以得到帮助与。 我正在创建一个位于状态栏中的工具
我正在开发一个在 Mac OS 状态栏中带有图标的应用程序。 我添加我的图标: self.statusItem = [[NSStatusBar systemStatusBar] statusItemW
我在 NSStatusItem 对象中有一个自定义 View 。该 View 显示图标。它还可以显示进度,但您必须调用 [self.statusitemview setProgressValue:th
我有一个 NSStatusItem,我想通过右键单击该项目来弹出一个菜单。我对 NSView 进行了子类化并覆盖了 - (void)rightMouseDown:(NSEvent *)event 方法
我在启动时显示一个 statusItem,如下所示: theItem = [[[NSStatusBar systemStatusBar] statusItemWithLength:NSVariable
我正在考虑一个想法,基本上我想要一个带有 NSPopoverController 的 NSStatusItem 。我读到了人们遇到的所有问题,但我只是想尝试一下。现在有干净的方法吗?我见过的所有版本都
我是一名 .Net 开发人员,需要将一个小项目移植到 Mac 中,所以我对 Objective C 几乎一无所知。事实上,下面的代码只是一堆捕获救命稻草和在黑暗中拍摄的代码。 尝试构建一个状态菜单程序
我使用黑色和透明的 PNG 创建状态项。我看到许多应用程序在突出显示时将颜色图标更改为白色(默认为蓝色背景),我想知道这个过程是自动的还是我必须调用 setAlternateImage 来手动更改它。
你们都知道 Mac OS X 中的菜单栏(或者更好地说 NSStatusBar)。 有些元素我可以移动,有些则不能。 我希望能够拖动我的应用程序的 NSStatusItem。 知道如何实现这个吗? 最
我有一个可变长度的NSStatusItem,我希望尽可能保持可见,即使这意味着只显示部分内容,但当我的项目足够宽以运行到应用程序的菜单栏,它完全隐藏。有没有办法知道何时发生这种情况,以便我可以缩小 V
我正在为 OS X 编写一个状态栏应用程序,我想在等待下载文件时使用动画“正在加载”gif 作为图标。 将 NSImage 中的 gif 传递给 NSStatusItem 的 setImage: 方法
我有一个带有附加菜单的 NSStatusItem,我使用全局热键触发该菜单。如果我单击菜单项,我会像平常一样突出显示,如果我使用热键,则不会触发突出显示。有谁知道触发高亮的方法吗? 我尝试过重写 Vi
我的菜单栏应用程序如何实现与 1Password 或 Dropbox 相同的行为: 单击他们的菜单栏图标或弹出框不会窃取焦点,例如例如,当我在 TextEdit 中并打开 1Password/Drop
我在名为 StatusMenuController 的类中创建一个 NSStatusItem,如下所示 class StatusMenuController: NSObject { let statu
可以将 NSStatusItem 的 behaviour 属性设置为 removalAllowed (NSStatusItemBehaviorRemovalAllowed)然后,用户可以使用拖放操作从
首先:我是 Swift 开发的新手。 我正在使用 this 教程制作一个弹出窗口,当我点击我的顶部栏图标时会出现该弹出窗口。 所以我的 AppDelehgate 代码是: func applicati
我已经为我的应用程序创建了一个 NSStatusItem,但希望它在使用 Control+F8 (Control+fn+f8) 时可以导航,就像系统项一样。 状态项在导航序列中被莫名其妙地跳过了。是否
我正在制作一个状态栏应用程序,它在单击 NSStatusItem 时显示 NSPopover,如下所示: 我添加了通过拖动边缘来调整弹出窗口大小的功能,方法是像这样子类化弹出窗口的 View : cl
我有一个仅限 NSStatusItem 的小型应用程序,带有设置窗口。从 NSStatusItem 中的菜单中,我想重新激活主窗口。 应用程序保留一个NSWindow实例,该实例设置为关闭时不释放。关
我有一个 OSX 应用程序,除了 NSStatusBar 中显示的图标之外,它还有自己的窗口。 NSStatusBar 的原因是使应用程序能够在主窗口关闭时在后台运行。当尝试单击状态栏图标时,我必须单
我是一名优秀的程序员,十分优秀!