如何防止NSCursor更改? [英] How to prevent a NSCursor from change?

查看:125
本文介绍了如何防止NSCursor更改?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在尝试防止更改光标时遇到问题。
我尝试将覆盖视图放置在整个窗口上,但是,如果在该覆盖下存在一个NSTextView,这将强制更改光标。我想防止这种情况,并保持箭头光标直到我的叠加视图将被删除。



覆盖cursorUpdate方法无效...

 覆盖func cursorUpdate(带有事件:NSEvent){
return

}



<谢谢!



甚至

解决方案

如果 NSTextView 是您的,则可以通过子类化并覆盖 mouseMoved:来获得所需的行为。 如果您进行搜索,则有几个示例



如果无法对文本视图进行子类化,最好的方法是使用 NSWindow


  • 使用 NSWindowStyleMaskBorderless 样式蒙版创建窗口。 / li>
  • 使窗口不透明,设置alpha,背景色

  • 使用 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(覆盖,有序:.above)

Now您可以将叠加视图添加为窗口的 contentView 。光标不会更改以响应以下视图。



另请参见


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

}

Thanks!

Even this (question 32447739) answer does not help. This solution is valid only if the overlay view is smaller than TextView.

解决方案

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.

这篇关于如何防止NSCursor更改?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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