如何在NSTextView上更改NSView和NSButton的鼠标样式 [英] How to change the mouse style of NSView and NSButton on NSTextView

查看:152
本文介绍了如何在NSTextView上更改NSView和NSButton的鼠标样式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

NSTextView顶部有一个NSView,并且NSTextview的范围大于NSView的范围.

NSView具有上面的一些NSButton等,效果很好,但是鼠标样式让我有些困惑.

我认为当鼠标移至NSView时,它一直是箭头样式,但不是,它始终显示iBeam样式.

因为它位于NSTextView上,所以当我的鼠标移至NSView时,它显示iBeam样式.我可以通过重写func mouseMoved(带有事件:NSEvent)实时更改鼠标NSCursor.arrow.set,尽管可以,但我会发现它会闪烁并偶尔显示iBeam.

是层的问题吗?或者我应该做的更好,至少不会闪烁.

我看了一些问题,但他们对这个问题的回答不太好,所以我再次叙述了这个问题,希望能得到确切的答案.

解决方案

NSTextView重置mouseMoved:事件中的鼠标光标.

如果您拥有NSTextView,则可以将其子类化并覆盖mouseMoved:. 此答案有一些很好的例子.

如果这不是您的选择,则需要将NSView(位于文本字段上方的那个)放在透明,无边界的NSWindow中.然后通过将其设置为子窗口来定位并保持该窗口在适当的位置.有关方法,请参见此答案./p>

There is a NSView on top of NSTextView, and the range of NSTextview is larger than the NSView range.

NSView has some of the above NSButton and so on, work very well, but the mouse style makes me a bit puzzled.

I think that when the mouse moves to NSView, it has been a arrow style, but not, it always displays the iBeam style.

Because it's on the NSTextView, so when my mouse moves to NSView, it shows the iBeam style. I change mouse NSCursor.arrow.set in real time by override func mouseMoved (with event: NSEvent), though it is okay, I find it will flash and occasionally show iBeam.

Is it the problem of the layer? Or what I should do is better, at least not flickering.

I looked at some questions, but they didn't answer this question very well, so I recount this question again, and hope to get the exact answer.

解决方案

The NSTextView resets the mouse cursor in it's mouseMoved: event.

If you own the NSTextView, you can subclass it and override mouseMoved:. This answer has some great examples.

If that's not an option for you, you will need to put your NSView (the one that's over the text field) in a transparent, borderless NSWindow. Then position and keep the window in place by making it a child window. See this answer for the methodology.

这篇关于如何在NSTextView上更改NSView和NSButton的鼠标样式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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