如何为 Mac OS X 制作可拖动的菜单栏图标
我正在为我正在开发的应用程序编写菜单栏图标。 但是 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
目前您无法使用 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.