c++ - 如果不是第一响应者,为什么我可以单击 NSButton?

标签 c++ cocoa first-responder nsresponder

我正在尝试在 C++ 中实现类似 NSResponder 的类,但我不明白的是:

所有键盘/鼠标交互都被发送到第一响应者,因此如果 NSTextField 当前是第一响应者,那么同一 View 中的另一个 NSButton 如何知道它已被单击?如果 textfield 不想要鼠标点击,它会将它发送到它的 superview,它的 superview 会将它发送到 View Controller 。因此鼠标单击事件永远不会到达按钮。

这可能是很明显的,但我现在无法理解。

最佳答案

All keyboard/mouse interactions are sent to the first responder

这是不正确的。来自Cocoa Event Handling Guide :

The window object … dispatches most events to the NSView object associated with the user action in an NSResponder message such as mouseDown: or keyDown:. …

The object receiving an event message differs slightly by type of event. For mouse and tablet events, the NSWindow object dispatches the event to the view over which the user pressed the mouse or stylus button. It dispatches most key events to the first responder of the key window.

在特定于这些事件类型的相关部分中重复了鼠标和按键事件路径之间的区别。

按钮“知道”它何时被点击,因为它就是被点击的东西。该窗口使用 -[NSView hitTest:] 方法找出鼠标光标下的内容。

关于c++ - 如果不是第一响应者,为什么我可以单击 NSButton?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23315019/

相关文章:

swift - tiffRepresentation 和 bitmapRepresentation 在 Base64 字符串编码方面的区别?

c++ - 如何在没有默认构造函数的情况下使用 std::transform 创建 std::array

macos - 如何中止 NSStepper 自动重复?

ios - 打破 Cocoa iOS 中 MVC 对象之间的循环依赖

cocoa - 方向键的 NSApplication 响应程序链

ios - UITableViewCell 中具有第一响应者状态的 UITextField 是否会阻止单元格重复使用?

ios - 以编程方式处理 uiwebview 中的文本字段

c++ - 错误 : 'strstr' was not declared in this scope

c++ - 如何在 symbian S60 Qt 应用程序中启动浏览器并加载 url?

c++ - Dll 未在 Firefox 中加载,但在自定义应用程序中加载