NSMenuItem 的视图(NSView 子类的实例)在悬停时不突出显示
我需要使用自定义 NSView
子类来绘制一些内容,但当用户悬停时它不会突出显示,并且当用户悬停时它不会关闭 NSMenu
点击它。有什么想法吗?
编辑
因此使用 -drawRect:
和 [[self enleadingMenuItem] isHighlighted]
我能够判断是否需要将视图绘制为突出显示并有机会这样做。我需要弄清楚的是如何做到这一点。
I need to use a custom NSView
subclass to draw some content, but it isn't drawing as highlighted when the user hovers and it doesn't dismiss the NSMenu
when the user clicks on it. Any ideas?
Edit
So using -drawRect:
and [[self enclosingMenuItem] isHighlighted]
I'm able to tell whether or not I need to draw the view as highlighted and am given the chance to do so. All I have to figure out is how to do that.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
也许你应该这样尝试:
Maybe you should try it this way:
我不确定我是否理解你的问题。我认为您的意思是:菜单打开,所有绘图都停止绘制。我认为这是因为打开的 NSMenu 停止了 UI' NSRunLoop 的线程。两者之一。您应该尝试在其他线程中进行线程安全的绘图。
I'm not sure if I understood your question. I think you mean the following: The Menu opened and all your drawings stopped drawing. I think this is because the opened NSMenu stopps the UI' NSRunLoop its thread. One of both. You should try to do your drawing thread-safe in an other thread.
这对我有用。我使用 Stackview。但这也应该适用于视图。
This worked for me. I use a Stackview. But this should work for views as well.