最好是用
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];
}