在Cocoa中,当悬停在圆形视图上时,更改光标的最好方法是什么? [英] In Cocoa, what is the best way to change the cursor when hovering over a circular view?

查看:203
本文介绍了在Cocoa中,当悬停在圆形视图上时,更改光标的最好方法是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想做什么

我有一个循环的自定义NSView子类,我想改变游标的外观鼠标悬停在视图的圆形部分,而不是在视图矩形的落在圆圈之外的部分。

I have a circular custom NSView subclass, and I want to change the appearance of the cursor when the mouse is hovering over the circular portions of the view, but not when over the portions of the view's rectangle that fall outside the circle.

这里有插图

到目前为止我知道的是

我知道如何通过NSCursor更改光标的外观。我认为,为矩形视图完成这个的最好的方法将是一个光标矩形。我知道我可以接收mouseMoved事件(当鼠标不在这个视图,使用mouseEntered和mouseExited时,应该关闭它们),并有一个简单,廉价的方法来确定一个点是否在感兴趣的区域。

I know how to change the appearance of the cursor through NSCursor. I think that the best way to accomplish this for a rectangular view would be with a cursor rectangle. I know that I could receive mouseMoved events (and ought to turn them off when the mouse isn't over this view, using mouseEntered and mouseExited), and have a simple, inexpensive way to determine if a point lies in the region of interest.

那么,问题是什么呢?

系统不会将mouseMoved事件发送到不是第一个响应者的视图。因此,如果我想获得mouseMoved事件,当鼠标悬停在我的视图,我需要从当前拥有它的firstResponder状态。如果一个文本视图有焦点,只需将鼠标移动到这样一个视图将被偷走,这是从可用性的角度来看是不可接受的。

As far as I can tell, the system does not send mouseMoved events to a view that is not the first responder. Therefore, if I want to get mouseMoved events when the mouse is hovering over my view, I need to steal firstResponder status from whoever currently has it. If a text view has the focus, simply moving the mouse over such a view would steal it away, which is simply unacceptable from a usability standpoint.

因此,我的问题沸腾下来:有更好的方法吗?我可以获得mouseMoved事件而不是第一个响应者吗?

Therefore, my question boils down to: is there a better way to do this? Can I get mouseMoved events without being the first responder?

谢谢!

:custom-views mouse-events NSCursor firstResponder
但是,我是一个SA noob,所以我不能。

I would have added the following tags: custom-views mouse-events NSCursor firstResponder But again, I'm an SA noob so I can't.

推荐答案

我认为你可能只需要重写NSView中的acceptsFirstResponder方法返回YES。如果没有,则视图将不会接收任何事件信息。

I think you may just need to override the acceptsFirstResponder method in your NSView to return YES. If you don't, then the view won't receive any event information.

这篇关于在Cocoa中,当悬停在圆形视图上时,更改光标的最好方法是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆