对状态栏项的 NSMenu 进行逆向工程
我想为状态栏项目创建一个菜单,例如 Tapbot 的 PastebotSync 应用程序中看到的菜单:
有人有吗想法如何实现菜单顶部与顶部齐平的自定义区域?
我已经尝试/想到了一些可能的方法:
- 带有视图的标准 NSMenuItem - 与菜单顶部不齐平
- 一些 hack-ish 代码将 NSWindow 放置在菜单顶部的区域上 -不太好,因为当菜单关闭时它不会很好地淡出
- 完全放弃 NSMenu 并使用 NSView - 还没有尝试过,但我真的不想制作一些假按钮或起作用的东西作为 NSMenuItems
有人有更好的想法或建议吗?
谢谢!
I'm want to create a menu for a status bar item like the one seen in Tapbot's PastebotSync application:
Does anyone have any ideas how to achieve the custom area at the top of the menu which is flush with the top?
I've tried/thought of a few potential ways of doing it:
- Standard NSMenuItem with a view - isn't flush with the top of the menu
- Some hack-ish code to place an NSWindow over the area at the top of the menu - not great as it doesn't fade out nicely with the menu when it closes
- Abandoning an NSMenu entirely and using an NSView instead - haven't tried this yet but I don't really want to have to make some fake buttons or something that act as NSMenuItems
Anyone have any better ideas or suggestions?
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果有人来看,我在 Gap above NSMenuItem 自定义视图上发布了一个解决方案
这是代码:
像这样使用它:
In case anyone comes looking, I posted a solution to this at Gap above NSMenuItem custom view
Here's the code:
Use it like this:
我在早期版本的 HoudahSpot 2 中也有同样的需求。我确实让它工作但有一个限制:我的代码使菜单底部带有方角。
我后来放弃了这个设置,因为 HoudahSpot 中的 BlitzSearch 功能变得需要更复杂的 UI,我在 NSMenu 中使用 NSView 时遇到了其他限制。
无论如何,这是处理这些额外 3 个像素的原始代码:
抱歉,我忘记了这一点:
I had the same need in early versions of HoudahSpot 2. I did get it working with one limitation: my code leaves the menu with square corners at the bottom.
I have since abandonned this setup, as the BlitzSearch feature in HoudahSpot grew to need a complexer UI, I ran into other limitations with using NSViews in a NSMenu.
Anyway, here is the original code taking care of those extra 3 pixels:
Sorry, I forgot that bit: