如何保持 NSStatusItem 的焦点直到再次切换它
我正在构建一个使用 NSStatusItem 的应用程序。我希望我的 NSStatusItem 在单击时打开并保持打开状态,直到用户再次单击 NSStatusItem。截至目前,它打开菜单,但当我单击远离它或单击另一个应用程序时, NSStatusItem 会失去焦点。我希望 NSStatusItem 的菜单保持打开状态,直到用户单击将其关闭。到目前为止,这是我制作 NSStatusItem 的代码。谢谢
-(void)awakeFromNib{
statusItem = [[[NSStatusBar systemStatusBar] statusItemWithLength:NSVariableStatusItemLength] retain];
[statusItem setMenu:statusMenu];
[statusItem setTitle:@"Status"];
[statusItem setHighlightMode:YES];
}
I'm building an app the uses a NSStatusItem. I'm wanting my NSStatusItem to open when clicked and stay open until the user clicks the NSStatusItem again. As of right now, it opens the menu but the NSStatusItem loses focus when I click away from it or click on another app. I would for the NSStatusItem's menu to stay open until the user clicks to close it. Here's my code so far just to make the NSStatusItem. Thanks
-(void)awakeFromNib{
statusItem = [[[NSStatusBar systemStatusBar] statusItemWithLength:NSVariableStatusItemLength] retain];
[statusItem setMenu:statusMenu];
[statusItem setTitle:@"Status"];
[statusItem setHighlightMode:YES];
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可能最好实现一个在单击状态项时打开的自定义窗口,而不是使用附加到状态项菜单的视图。
菜单具有明确定义的打开/关闭/鼠标跟踪行为,尝试在子类中更改它可能会令人沮丧。
You would probably be best off implementing a custom window that opens when you click the status item rather than using a view attached to the status item's menu.
Menus have well-defined opening/closing/mouse tracking behaviour and trying to change it in a subclass will probably just be frustrating.