是否存在检测小鼠何时离开活跃的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];
}