如何为 Mac OS X 制作可拖动的菜单栏图标

发布于 2024-07-12 03:40:05 字数 132 浏览 6 评论 0原文

我正在为我正在开发的应用程序编写菜单栏图标。 但是 NSStatusBar 类没有可以通过 cmd+鼠标左键拖动来使图标可拖动的方法。

如何使用 Objective-C 代码使菜单栏图标可拖动?

谢谢 :)

I am in the process of writing a menubar icon for an app i'm developing. However the NSStatusBar class does not have a method which would make the icon draggable, via cmd+left mouse drag.

How do you make your menubar icon draggable with Objective-C code?

Thank you :)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

自此以后,行同陌路 2024-07-19 03:40:05

目前您无法使用 NSStatusBar 来完成此操作。 NSMenuExtra 会按照你想要的方式运行,但不幸的是它不是公共 Cocoa API 的一部分,并且据我了解(我自己没有使用过它)甚至需要一些技巧才能使其工作。 此外,NSStatusBar 将更容易集成到现有应用程序中,NSMenuExtra 更像是系统加载的单独包。

在我看来,依赖私有 API 向您的应用程序添加此类主要功能并不是一个好主意。 我会坚持使用 NSStatusBar,大多数用户都会习惯其他应用程序的行为,幸运的话,Mac OS X 的未来版本将允许像 NSMenuExtra 一样拖动图标。

You can't currently do it with NSStatusBar. NSMenuExtra will behave the the way you want, but unfortunately it's not part of the part of the public Cocoa API, and from what I understand (I haven't used it myself) takes a bit of a hack to even get it working. Also NSStatusBar will be easier to integrate into an existing application, NSMenuExtra is more of a separate bundle that's loaded by the system.

In my opinion it's not a good idea to depend on private APIs to add major functionality like this to your app. I would stick with NSStatusBar, most users will be used to the behavior from other applications, and with any luck a future version of Mac OS X will allow dragging the icon the same way NSMenuExtra works.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文