C-V*_*rel 5 macos cocoa nsview nscursor swift
I have a problem while I try to prevent a cursor from changing.
I try to put an overlay view over entire window, but, if under that overlay exist an NSTextView, this will force cursor to change. I want to prevent that, and keep the arrow cursor until my overlay view will be removed.
Overriding the cursorUpdate method does not work:
override func cursorUpdate(with event: NSEvent) {
return
}
Run Code Online (Sandbox Code Playgroud)
Thanks!
即使这个问题的答案也无济于事。此解决方案仅在叠加视图小于 TextView 时有效。
如果是你的,你可以通过子类化和覆盖那里NSTextView来获得你想要的行为。如果您搜索,有几个可用的示例。mouseMoved:
如果不能选择对文本视图进行子类化,那么最好的办法是使用NSWindow覆盖层。
NSWindowStyleMaskBorderless。addChildWindow:ordered定位叠加层这个答案很好地解释了这一点。
像这样的东西:
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)
Run Code Online (Sandbox Code Playgroud)
现在您可以将覆盖视图添加为窗口的contentView. 光标不会随着下面的视图而改变。
也可以看看。
| 归档时间: |
|
| 查看次数: |
543 次 |
| 最近记录: |