If the NSTextView
is yours, you can get the behaviour you want by subclassing and overriding mouseMoved:
there. There are several examples available, if you search.
If subclassing the text view is not an option, the best thing would be to use an NSWindow
for your overlay.
- Create the window with the
NSWindowStyleMaskBorderless
style mask.
- Make the window opaque, set the alpha, background color
- Use
addChildWindow:ordered
to position your overlay
This answer explains it quite well.
Something like this:
var rect = NSRect(x: self.window.frame.origin.x, y: self.window.frame.origin.y, width: self.window.contentView.frame.size.width, height: self.window.contentView.frame.size.height)
var overlay = NSWindow.init(contentRect: rect, styleMask: .borderless, backing: .buffered, defer: false)
overlay.backgroundColor = .red
overlay.isOpaque = false
overlay.alphaValue = 0.5
self.window.addChildWindow(overlay, ordered: .above)
Now you can add your overlay view as the window's contentView
. The cursor will not change in response to the views below.
See also.