macos – Mavericks和NSStatusItem的多个监视器的自定义视图

macos – Mavericks和NSStatusItem的多个监视器的自定义视图,第1张

概述由于小牛每个屏幕都有自己的状态栏.这也意味着在状态栏中运行的应用程序(使用NSStatusItem)理论上有多个NSStatusItem对象关联.实际上,尽管用户可能会看到NSStatusItem的多个“实例”,但它只是一个(我已经测试过了).现在,当您在状态图标中使用自定义视图时会出现以下问题:当用户单击状态图标时,我使用drawStatusBarBackgroundInRect方法以编程方式“ 由于小牛每个屏幕都有自己的状态栏.这也意味着在状态栏中运行的应用程序(使用NsstatusItem)理论上有多个NsstatusItem对象关联.实际上,尽管用户可能会看到NsstatusItem的多个“实例”,但它只是一个(我已经测试过了).现在,当您在状态图标中使用自定义视图时会出现以下问题:当用户单击状态图标时,我使用drawStatusbarBackgroundInRect方法以编程方式“突出显示”它.问题是状态图标的每个“实例”(每个屏幕一个)都会突出显示,尽管用户只需点击一个.此行为与没有自定义视图的状态图标不同.有没有办法正确实现这个?

举个好例子,只需在使用多个显示器时点击DropBox状态图标即可.你会注意到在另一个屏幕上选择了图标.

解决方法 来自JlinX Apple Dev Forums提到的Apple的回应:

Status Items with multiple menu bars

10.9 introduces multiple menu bars,each of which draws the status items. If your status item has a custom vIEw,this vIEw is positioned in one menu bar,and other menu bars get a “clone”,which looks IDentical. The clones are not exposed in the API. The clones are drawn by redirecting your custom vIEw’s drawing into another window. This means that your status item should not make assumptions about the drawing destination. For example,it should not assume that a call to drawRect: is destined for the vIEw’s window,or that the resolution of the drawing destination matches the resolution of the status item’s screen. You must also not assume that the status item is on any particular display,except as described below. The clones are only redrawn in NSDefaultRunLoopMode. This allows the status item to limit highlighting to one display,by driving the run loop in another mode,such as NSEventTrackingRunLoopMode. For example,if you wish to simulate a menu,you would implement mouseDown: to show your window,and run the run loop in NSEventTrackingRunLoopMode until you determine that the window should be dismissed. While the run loop is in this mode,only the true status item will redraw. Clone status items will not redraw,and therefore they will not show any highlight applIEd to the true status item. When a clone status item is clicked,the clone exchanges locations with the true status item. This means that the location and screen of the status item window is reliable from within mouseDown:. You can access this information from your custom vIEw,for example,using [[vIEw window] screen] to position a window on the same screen as the status item.

总结

以上是内存溢出为你收集整理的macos – Mavericks和NSStatusItem的多个监视器的自定义视图全部内容,希望文章能够帮你解决macos – Mavericks和NSStatusItem的多个监视器的自定义视图所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/web/1023118.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-23
下一篇 2022-05-23

发表评论

登录后才能评论

评论列表(0条)

保存