在给NSView 添加trackingArea后,鼠标不动,滚动view, mouseExited: 不调用
- (void)updateTrackingAreas {
[self removeTrackingArea:_trackingArea];
_trackingArea = [[NSTrackingArea alloc] initWithRect:self.bounds options:NSTrackingActiveInKeyWindow |NSTrackingMouseMoved | NSTrackingMouseEnteredAndExited owner:self userInfo:nil];
[self addTrackingArea:_trackingArea];
}
解决方法:
- (void)updateTrackingAreas {
[self removeTrackingArea:_trackingArea];
_trackingArea = [[NSTrackingArea alloc] initWithRect:self.bounds options:NSTrackingActiveInKeyWindow |NSTrackingMouseMoved | NSTrackingMouseEnteredAndExited owner:self userInfo:nil];
[self addTrackingArea:_trackingArea];
//mouseExited isn't called when mouse leaves trackingArea while scrolling
NSPoint mouseLocation = [[self window] mouseLocationOutsideOfEventStream];
mouseLocation = [self convertPoint: mouseLocation
fromView: nil];
if (NSPointInRect(mouseLocation, [self bounds]))
{
[self mouseEntered: [NSApp currentEvent]];
}
else
{
[self mouseExited: [NSApp currentEvent]];
}
[super updateTrackingAreas];
}