问题
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.
回答1:
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.
来源:https://stackoverflow.com/questions/48618684/how-to-change-the-mouse-style-of-nsview-and-nsbutton-on-nstextview