如何有效地为 NSView 设置 Cursor?

发布于 2024-09-18 13:04:46 字数 354 浏览 1 评论 0原文

我有一个 NSView,它正在绘制一组不规则形状(和重叠)的应用程序管理对象:显然无法通过有效使用非重叠矩形来描述。

我想在光标位于这些对象之一上时更改光标。 通常的方法似乎是设置跟踪矩形来响应 -(void)resetCursorRects,每个矩形与不同的光标相关联,但我无法将其应用于这种情况。

我只知道在处理 -(void)mouseMoved:(NSEvent *)theEvent 消息时哪个对象位于光标下方最上面...所以我需要更改光标。

这合适吗? NSView 什么时候会尝试将光标设置为通常的箭头?我不想以闪烁的光标结束,因为 NSView 将其设置为不同消息上的默认值。

I have an NSView that is drawing a collection of irregularly shaped (and overlapping) application managed objects: that obviously can't be described by efficiently using non overlapping rectangles.

I want to change the cursor when it it over one of these objects.
The usual method seems to be to set up tracking rects in response to -(void)resetCursorRects, each associated with a different cursor, but I can't apply that to this situation.

I only know which object is top most under the cursor when processing -(void)mouseMoved:(NSEvent *)theEvent messages... so I need to change the cursor then.

Is this appropriate? When is NSView going to try and set the cursor to the usual arrow? I don't want to end up with a flickering cursor because NSView is setting it to default on a different message.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

爺獨霸怡葒院 2024-09-25 13:04:46

考虑使用跟踪区域:使用跟踪区域对象。特别是 NSTrackingCursorUpdate。这样,您就可以专门响应各种类型的跟踪事件。我认为这有助于避免您所描述的情况。

Consider using tracking areas: Using Tracking-Area Objects. Particularly, NSTrackingCursorUpdate. This way, you can respond specifically to the individual types of tracking events. I think this helps avoid the situation you described.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文