gpt4 book ai didi

macos - Mavericks 和 NSStatusItem 的具有多个监视器的自定义 View

转载 作者:行者123 更新时间:2023-12-03 16:06:47 25 4
gpt4 key购买 nike

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

举个很好的例子,当您使用多个显示器时,只需单击 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 的具有多个监视器的自定义 View ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20021149/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com