无法弄清楚如何处理鼠标在NSCell
(或NSTextAttachmentCell
)上的移动。这可能吗?
最佳答案
您可以在包含单元格的 View 中添加跟踪区域,并在该 View 中实现 mouseEntered: 和 mouseExited: (如果还需要,还可以实现 mouseMoved)。下面是一个示例,其中我添加了一个按钮的跟踪区域(按钮是按钮的 IBOutlet)。我在 View 的 awakeFromNib 方法中添加了以下代码:
NSTrackingArea *buttonArea = [[NSTrackingArea alloc] initWithRect:self.button.frame options:NSTrackingMouseEnteredAndExited|NSTrackingMouseMoved|NSTrackingActiveInActiveApp owner:self userInfo:nil];
[self addTrackingArea:buttonArea];
当光标进入按钮框架时,这将导致 View 接收 mouseEntered、mouseMoved 和 mouseExited 消息。
关于cocoa - 处理 NSCell 上的鼠标悬停(NSTextAttachmentCell),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10352967/