如何为Mac OS X制作可拖动的菜单栏图标 [英] How would I make a draggable Menubar icon for Mac OS X

查看:121
本文介绍了如何为Mac OS X制作可拖动的菜单栏图标的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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.

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

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

谢谢:)

推荐答案

您目前无法使用NSStatusBar进行此操作. NSMenuExtra会按照您想要的方式运行,但是不幸的是,它不是公共Cocoa API的一部分,从我的理解(我自己没有使用过)来看,需要一点技巧才能使其正常工作.另外,NSStatusBar将更易于集成到现有应用程序中,而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.

我认为,依靠私有API在您的应用中添加类似的主要功能不是一个好主意.我会坚持使用NSStatusBar,大多数用户将习惯于其他应用程序的行为,如果运气好的话,将来的Mac OS X版本将允许以与NSMenuExtra相同的方式拖动图标.

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.

这篇关于如何为Mac OS X制作可拖动的菜单栏图标的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆