鼠标离开 NSWindow 实例的事件

Event for mouse leaving a NSWindow instance

是否有检测鼠标何时离开活动 NSWindow 边界的机制?

我已经尝试覆盖 mouseMoved: 方法,但是当鼠标在 NSWindow 范围之外时不会调用该方法。

最好用NSTrackingArea

- (void)configureTrackingArea
{
    NSRect trackingRect = self.window.contentView.frame
    NSTrackingAreaOptions trackingOptions = NSTrackingMouseEnteredAndExited | NSTrackingActiveInKeyWindow;
    NSTrackingArea *trackingArea = [[NSTrackingArea alloc] initWithRect:trackingRect options:trackingOptions owner:self userInfo:nil];

    NSView *contentView = [[self window] contentView];
    [contentView addTrackingArea:trackingArea];
}


- (void)mouseEntered:(NSEvent *)event
{
    [[self window] addChildWindow:[self previewWindow] ordered:NSWindowAbove];
}

- (void)mouseExited:(NSEvent *)event
{
    [self hidePreviewWindow];
}