如何有效地为 NSView 设置 Cursor?
我有一个 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
考虑使用跟踪区域:使用跟踪区域对象。特别是 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.