我正在编写一个通知系统,就像 growl 一样。通知是一个窗口,其级别设置为 NSModalPanelWindowLevel。唯一的问题是,我在该窗口中有一个按钮,当用户想要单击该按钮时,他/她必须单击两次。但是,例如,在 growl 中,无论您打开哪个窗口,您只需单击通知,它就会记录一次单击。 那么是不是水平问题呢?如果是这样,我应该将其设置为什么?谢谢
最佳答案
在构成窗口 View 内容的自定义控件中,您可能希望覆盖 NSView
的 -acceptsFirstMouse:
返回YES
的方法:
Discussion
The receiver can either return a value unconditionally or use the location of
theEvent
to determine whether or not it wants the event. The default implementation ignorestheEvent
and returnsNO
.Override this method in a subclass to allow instances to respond to click-through. This allows the user to click on a view in an inactive window, activating the view with one click, instead of clicking first to make the window active and then clicking the view. Most view objects refuse a click-through attempt, so the event simply activates the window. Many control objects, however, such as instances of
NSButton
andNSSlider
, do accept them, so the user can immediately manipulate the control without having to release the mouse button.
关于objective-c - 类似 nswindow 级别的 growl 通知,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5656266/