4

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.

Simon
  • 438
  • 4
  • 14

1 Answers1

2

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.

TheNextman
  • 12,428
  • 2
  • 36
  • 75
  • If you have tried it, you will find that this is quite different from NSTextField. – Simon Apr 02 '18 at 21:33
  • I think that for the purpose of the question, `NSTextField` and `NSTextView` work pretty much the same. I recommend you to read https://stackoverflow.com/help/how-to-ask, and follow the advice of "Include just enough code to allow others to reproduce the problem. For help with this, read How to create a Minimal, Complete, and Verifiable example". Because there are plenty of similar questions and answers out there, so if something is not working in your case, more is needed than "they didn't answer this question very well" to provide help to you. – TheNextman Apr 02 '18 at 22:47